Generics leaking pub(crate) types?

I’m trying to create a “internal implementation only” solution using generics and traits.

The logic works fine but it seems I can’t export the “wrapper” struct that uses the internal implementations sort of as-needed without making those implementation structs also fully public.

Example at https://github.com/almindor/rust_example_ws (needs sep. crate to be vibisle, playground wouldn’t work for this).

Error is error: typelib123::internal::ImplementorCrateOnlyis private in main on line 6

I’m not sure why this doesn’t allow keeping the ImplementorCrateOnly as crate-only given there are no entry-points to allow accessing the value behind the ImplementorCrateOnly type anywhere inside VisibleToUsers

impl<X> VisibleToUsers<internal::ImplementorCrateOnly<X>>
where X: Sized + Debug
{
    pub fn from_args_for_specific_impl(x: X) -> Self {
        VisibleToUsers::new(internal::ImplementorCrateOnly::new(x))
    }    
}

Any public signature cannot contain something that’s private anywhere in it. I’m actually surprised that this impl even shows up in rustdoc.

You can freely make things pub in modules that are inaccessible to users, and it will accomplish approximately what you’re trying to do. (users can’t name them unless they happen to appear as an associated type somewhere, and they won’t get a page in the docs)

mod private {
    pub trait PubInNameOnly {}
}
2 Likes

Oh I see so if I have a private mod I can freely use pub for the contents as needed by the “top level” wrappers. I thought if I make things pub it’d be visible by users.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.