Skip to content

Instantly share code, notes, and snippets.

@kiljacken
Last active September 2, 2022 11:22
Show Gist options
  • Save kiljacken/90655b7649177cb74a02f1470b13528c to your computer and use it in GitHub Desktop.
Save kiljacken/90655b7649177cb74a02f1470b13528c to your computer and use it in GitHub Desktop.
// 1: Only my crate can implement *and* use it (plain visibilty)
pub(crate) trait AllocImpl {}
// 2: Only my module can implement the trait, others can use it
mod private {
pub trait Sealed {}
}
pub trait AllocImpl: private::Sealed {}
// 3: Other crates can implement but I have some private stuff only my module must do
pub trait AllocImpl {}
trait AllocImplExt: AllocImpl {
// the private stuff, implementation can only be in terms of things exposed in AllocImpl
}
impl<T: AllocImpl> AllocImplExt for T {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment