Last active
September 22, 2021 08:44
-
-
Save apua/58635141894535ccbb3fda9328dd18b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mod a { | |
pub const _A1: i32 = 1; | |
const _A2: i32 = 1; | |
mod aa { | |
pub const _A3: i32 = 1; | |
pub const _A4: i32 = 1; | |
} | |
/// :mod:`aa` is accessible in :mod:`a` | |
const _: i32 = aa::_A3; | |
/// export `_A4` from :mod:`aa` | |
pub use aa::_A4; | |
} | |
/// :mod:`a` is accessible | |
/// even though, member has to be public | |
fn _a() { | |
let _ = a::_A1; | |
//let _ = a::_A2; // constant `A2` is private | |
//let _ = a::aa::_A3; // module `aa` is private | |
//let _ = a::aa::_A4; // module `aa` is private | |
//let _ = a::_A3; // constant import `A3` is private | |
// exported even :mod:`let _ = aa` is not public | |
let _ = a::_A4; | |
} | |
mod b { | |
pub mod bb { | |
pub const _B1: i32 = 1; | |
const _B2: i32 = 1; | |
} | |
} | |
/// nested public module | |
fn _b() { | |
let _ = b::bb::_B1; | |
//let _ = b::bb::_B2; // constant `B2` is private | |
} | |
mod c { | |
const _C1: i32 = 1; | |
pub(self) const _C2: i32 = 1; | |
} | |
/// pub(self) == private | |
fn _c() { | |
//let _ = c::_C1; // constant `C1` is private private constant | |
//let _ = c::_C2; // constant `C2` is private private constant | |
} | |
/// pub(crate) ~= pub | |
/// note that external can access pub, but not pub(crate) | |
mod d { | |
mod dd { | |
pub const _D1: i32 = 1; | |
pub(crate) const _D2: i32 = 1; | |
pub(in crate) const _D3: i32 = 1; | |
} | |
pub mod dp { | |
pub const _D4: i32 = 1; | |
pub(crate) const _D5: i32 = 1; | |
pub(in crate) const _D6: i32 = 1; | |
} | |
pub mod dn { | |
pub mod n { | |
pub const _D7: i32 = 1; | |
pub(crate) const _D8: i32 = 1; | |
pub(in crate) const _D9: i32 = 1; | |
} | |
} | |
/// accessible as well, even if not at the top of crate | |
const _: i32 = dn::n::_D7; | |
const _: i32 = dn::n::_D8; | |
const _: i32 = dn::n::_D9; | |
} | |
fn _d() { | |
//let _ = d::dd::_D1; // module `dd` is private | |
//let _ = d::dd::_D2; // module `dd` is private | |
//let _ = d::dd::_D3; // module `dd` is private | |
let _ = d::dp::_D4; | |
let _ = d::dp::_D5; | |
let _ = d::dp::_D6; | |
} | |
/// unable to re-export members | |
/// except for macro | |
mod e { | |
const _E1: i32 = 1; | |
//pub use _E1; // `_E1` is private, and cannot be re-exported | |
//pub(crate) use _E1; | |
//pub(in crate) use _E1; | |
//pub(in super) use _E1; | |
macro_rules! e2 { () => {}; } | |
//pub use _e2; //unresolved import `_e2` | |
pub(crate) use e2; | |
#[macro_export] | |
macro_rules! e3 { () => {}; } | |
mod e4 {} | |
//pub use e4; // `e4` is private, and cannot be re-exported | |
//pub(crate) use e4; | |
} | |
fn _e() { | |
//e2!(); // cannot find macro `e2` in this scope | |
e::e2!(); | |
e3!(); | |
//e::e3!(); // failed to resolve: could not find `e3` in `e` | |
} | |
/// pub(super) is private for outer scope | |
/// and able to export | |
mod f { | |
mod n { | |
mod nn { | |
pub(self) const _F1: i32 = 1; | |
pub(super) const _F2: i32 = 1; | |
pub(crate) const _F3: i32 = 1; | |
} | |
//const _: i32 = nn::_F1; //constant `_F1` is private | |
const _: i32 = nn::_F2; | |
const _: i32 = nn::_F3; | |
pub mod np { | |
pub(self) const _F4: i32 = 1; | |
pub(super) const _F5: i32 = 1; | |
pub(crate) const _F6: i32 = 1; | |
} | |
/// export `_A5` from :mod:`np` | |
pub const _F7: i32 = np::_F5; | |
} | |
//const _: i32 = n::nn::_F1; //module `nn` is private | |
//const _: i32 = n::nn::_F2; //module `nn` is private | |
//const _: i32 = n::nn::_F3; //module `nn` is private | |
//const _: i32 = n::np::_F4; //constant `_F4` is private | |
//const _: i32 = n::np::_F5; //constant `_F5` is private | |
const _: i32 = n::np::_F6; | |
const _: i32 = n::_F7; | |
} | |
/// pub(in path) | |
mod g { | |
pub mod h { | |
pub mod i { | |
/// also: | |
/// ``` | |
/// const _G1: i32 = 1; | |
/// pub(self) const _G1: i32 = 1; | |
/// pub(in self) const _G1: i32 = 1; | |
/// pub(in super::i) const _G1: i32 = 1; | |
pub(in crate::g::h::i) const _G1: i32 = 1; | |
/// also: | |
/// ``` | |
/// pub(in super) const _G2: i32 = 1; | |
pub(in crate::g::h) const _G2: i32 = 1; | |
pub(in crate::g) const _G3: i32 = 1; | |
/// also: | |
/// ``` | |
/// pub const _G4: i32 = 1; | |
/// pub(crate) const _G4: i32 = 1; | |
pub(in crate) const _G4: i32 = 1; | |
mod j { | |
const _: i32 = crate::g::h::i::_G1; | |
const _: i32 = super::_G2; | |
//const _: i32 = _G3; //cannot find value `_G3` in this scope | |
} | |
} | |
//const _: i32 = i::_G1; //constant `_G1` is private | |
const _: i32 = i::_G2; | |
mod k { | |
//const _: i32 = super::i::_G1; //constant `_G1` is private | |
const _: i32 = super::i::_G2; | |
} | |
} | |
//const _: i32 = h::i::_G2; //constant `_G2` is private | |
const _: i32 = h::i::_G3; | |
} | |
fn _g() { | |
//let _ = g::h::i::_G3; //constant `_G3` is private | |
let _ = g::h::i::_G4; | |
} | |
fn main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment