Working rfc1422 visibility example?


#1

I’m cutting and pasting example code from rfc 1422:

https://github.com/rust-lang/rfcs/blob/master/text/1422-pub-restricted.md

but each seems to give errors in nightly. For example:

https://play.rust-lang.org/?gist=086335dc60e28570f384f9c8d3e734ea&version=nightly

is something broken? or am I grossly misreading something.

If anyone has a working example that restricts access to a function to a specific module that’d be great.


#2

looks like the doc’s have some examples that work (is it expected that rfc code is gives parse errors)?

https://doc.rust-lang.org/beta/reference/visibility-and-privacy.html

Adapting the example in the doc’s, I still can’t get something like this to work:

    pub mod outer_mod {
        use super::b_mod;
        
        // error[E0578]: cannot find module `b_mod` in the crate root
        //   [no --explain for E0578]
        pub(in b_mod) fn b_visible_fn() {}

        // but this works!
        pub fn a() { b_mod::b(); }
    }
    pub mod b_mod {
            pub fn b() {}
    }

    fn main() { }

#3

You missing the date is from 2015. RFCs are just drafts.
The visibility restriction is stable now. Think syntax was in (at least) some release notes.
First example just add in in front of a.

In embedded code. If you move the mod above you will see

error: visibilities can only be restricted to ancestor modules

#4

I don’t think this will work because b_mod isn’t a parent module of outer_mod (it’s a sibling)