I am a rust newbie and I came across this kind of function declaration in an open source repository pub(crate) fn
I have never seen this kind of syntax before so I was wondering what is it used for?
I am a rust newbie and I came across this kind of function declaration in an open source repository pub(crate) fn
I have never seen this kind of syntax before so I was wondering what is it used for?
It defines the level of visibility. The levels of visibility (privacy) are explained here:
Syntax Visibility : pub | pub ( crate ) | pub ( self ) | pub ( super ) | pub ( in SimplePath )
pub(in path) makes an item visible within the provided path. path must be a parent module of the item whose visibility is being declared.
pub(crate) makes an item visible within the current crate.
pub(super) makes an item visible to the parent module. This is equivalent to pub(in super).
pub(self) makes an item visible to the current module. This is equivalent to pub(in self).
So pub(crate) fn find_key<K, S>(keys: &Chunk<K, S>, key: &K) -> Option<usize>
makes the find_key
function public (available for use) within the crate, but not outside of it.