Cannot use Bytes crate from git, but crate works

Something strange is happening when I try to use the bytes crate via git instead of the crate from It seems the BytesMut type no longer impls BufMut. I have a small reproducing example here:


name = "foo"
version = "0.1.0"
edition = "2021"

#bytes = "1.6"
bytes = { git = "GitHub - tokio-rs/bytes: Utilities for working with bytes", branch = "master" }
tokio = { version = "*", features = ["full"] }

use tokio::fs::File;
use tokio::io::{self, AsyncReadExt};
use bytes::BytesMut;

async fn main() -> io::Result<()> {
let mut f = File::open("foo.txt").await?;
let mut buffer = BytesMut::with_capacity(10);
f.read_buf(&mut buffer).await?;

Error when using the dependency from git instead of as a crate:

error[E0277]: the trait bound BytesMut: bytes::buf::buf_mut::BufMut is not satisfied
--> src/
10 | f.read_buf(&mut buffer).await?;
| -------- ^^^^^^^^^^^ the trait bytes::buf::buf_mut::BufMut is not implemented for BytesMut
| |
| required by a bound introduced by this call
= help: the following other types implement trait bytes::buf::buf_mut::BufMut:
bytes::buf::chain::Chain<T, U>
&mut T
&mut [u8]
&mut [MaybeUninit]
note: required by a bound in tokio::io::AsyncReadExt::read_buf
--> /.cargo/registry/src/
246 | fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
| -------- required by a bound in this associated function
249 | B: BufMut + ?Sized,
| ^^^^^^ required by this bound in AsyncReadExt::read_buf

I'd be thankful for any pointers on what's going on

It's because tokio also depends on bytes, but it depends on the version that is considered different from your github version, so now you end up with two different versions of bytes. Each copy has different traits.

You need to use a [patch.crates-io] section instead. See Overriding Dependencies - The Cargo Book for more info.