Description
I think this suggestion can be best explained with an example. Suppose we have a library crate with this lib.rs
extern crate byteorder;
pub struct MyStruct { /* details are irrelevant */ }
impl MyStruct {
pub fn deserialize::<BO: byteorder::ByteOrder>(data: &[u8]) -> Self {
// implementation irrelevant
}
The problem with this crate is that in order to use it, a user must explicitly add byteorder
crate to dependencies, which is annoying. However, if the crate had pub extern crate byteorder;
or re-exported byteorder::{ByteOrder, LE, BE}
, no additional definitions would be necessary.
So I suggest to detect instances of usage of types from dependencies in interfaces and warn if they aren't public/re-exported.
Of course, there is a difficulty with traits used like in this example (re-exporting byteorder::ByteOrder
isn't enough but there is nothing in the interface of the deserialize
method to suggest that). One way to address it would be suggesting to either make the whole dependency public or re-export all public types implementing that trait.
What do you think?