Skip to content

Instantly share code, notes, and snippets.

@matklad
Last active November 10, 2015 20:50
Show Gist options
  • Save matklad/7e5027de4cf4630220f2 to your computer and use it in GitHub Desktop.
Save matklad/7e5027de4cf4630220f2 to your computer and use it in GitHub Desktop.
pub mod references {
pub mod psi_ref {
// Unit like struct, the type with only one member
pub struct Ref;
impl Ref {
pub fn resolve(&self) -> &Ref {
// resolve is not pub, but we can use anything from the parent module's scope
super::resolve::do_resolve(self)
}
}
}
// Note that there is no `pub` here.
mod resolve {
use super::psi_ref::Ref;
pub fn do_resolve(r: &Ref) -> &Ref {
r
}
}
}
fn main() {
use references::psi_ref::Ref;
let r = Ref;
// can call resolve via ref
r.resolve();
// this fails, because mod resolve is not pub
// references::resolve::do_resolve(&r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment