SemVer compatibilty of exported declarative macros using 3rd party dependencies

I agree with you that it seems undesirable to reexport a specific version of hashbrown.

If you take out the mention of HashMap entirely, then it's just a FromIterator call with an unknown result type, which can work with many different kinds of maps. So, I would suggest that you provide that version of the macro, which is 100% future-proof.

You can then offer a separate macro which wraps it and constrains the result type:

($($args:tt)*) => {
    let map: ::hashbrown::HashMap<_, _> = map!($($args:tt)*);
    map
}

or perhaps even, instead of trying to pin down the type to a crate, just mention unqualified HashMap and lets that be whatever type the caller imported. (A violation of macro hygiene, but one that can't truly be avoided, and might be useful.)

1 Like