Last active
November 10, 2015 20:50
-
-
Save matklad/7e5027de4cf4630220f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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