I just noticed the following, which I found a bit weird:
pub trait MyTrait {
pub fn my_function;
}
This is not allowed currently - rust complains about the pub
modifier in front of the fn my_function
:
error: expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `pub`
Why not rethink this a bit - this is just my idea:
pub trait { pub fn }
means public trait and method can be implemented from outside the crate
pub trait { fn }
means that the trait is public and can be implemented, but the function cannot be implemented. If all functions of a trait are private (to the trait), then the trait itself is public, but it can't be implemented from outside the current library.
trait { pub fn }
is an error, can't leak public implementable function from crate-internal trait
trait { fn }
- both trait and function are only public to the crate they're in.
I have also thought of using pub(trait)
modifier as an extension to restricted types.
When there is a pub
in front of a trait, it should be documented, when there is a pub
in front of a fn, it should be documented.
I think this solves the problem for Rayon:
This would result in:
pub trait Pattern {
fn find_in() { } /* find_in is not marked pub and cannot be called outside of rayon*/
}
Additionally, find_in
would be hidden from the documentation.
This is also something I would like to adress - rustdoc should differentiate between the current crate and external crates. If you are working with your own library, it is useful to document private functions, but if other people use your library then you may not want private functions to be documented. Just a thought.