Use bincode derive macro if bincode is exported by dependency

One of my crates (A) uses bincode. Another one (B) depends on this crate and uses bincode too. I'm trying to make crate B use bincode exported from crate A. It works fine with functions from bincode, but not with macros. bincode derive macros seem to expand to code which uses ::bincode::... instead of bincode::... for example. So it seems like I simply can’t use these macros without depending on bincode directly.

Is it really so or am I missing some possible workarounds?

Note that bincode is unmaintained. That being said, you can change the ::bincode default import path via the #[bincode(crate = "::your_crate::bincode")] container attribute. E.g.:

#[derive(Encode, Decode, PartialEq, Debug)]
#[bincode(crate = "::your_crate::bincode")]
struct Entity {
    x: f32,
    y: f32,
}
3 Likes