Given the proposed privacy resolution rules ( https://github.com/mozilla/rust/issues/8215#issuecomment-24762188 ) there exists a concept of crate-scope for items: these can be used within the implementation of the crate, but are inaccessible from other crates. This is easy to do by introducing a private module:

mod private
{
   pub fn crate_scoped_fn();
   pub trait CrateScopedTrait;
   pub struct CrateScopedStruct;
}

It's not clear to me whether or not this is possible (or whether it should be) for non-trait implementations. Right now, if I do this:

pub struct S;
mod private
{
   impl super::S
   {
       pub fn new() -> super::S { super::S }
       pub fn crate_local_api(&self) -> {}
   }
}

I find that the associated function can't be used at all within a crate or cross crate (issue #9584), while the method resolves in both cases, but does not link cross-crate. What should happen in this case? I'd prefer for the function and method to resolve within a crate, but not cross crate.

Notably, this is not how trait implementations work today, as those are resolved by looking at the location/privacy of the trait and not the implementation. I think crate-scoped methods and associated functions are very useful though, and it's worthwhile to have a different rule for them.

Or maybe there should be an explicit keyword for the crate scope and not bother with these bizarre privacy rules. Or maybe I am missing an alternate way to accomplish this?

-SL
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to