@@ -183,3 +183,70 @@ macro_rules! lrlex_mod {
183183 include!( concat!( env!( "OUT_DIR" ) , "/" , $path, ".rs" ) ) ;
184184 } ;
185185}
186+
187+ /// This private module with pub items which is directly related to
188+ /// the "Sealed trait" pattern. These items are used within the current
189+ /// crate. See `unstable_api` module for enabling usage outside the crate.
190+ mod unstable {
191+ #![ allow( unused) ]
192+ #![ allow( unreachable_pub) ]
193+ pub struct UnstableApi ;
194+ pub trait UnstableTrait { }
195+ }
196+
197+ /// A module for lifting restrictions on visibility by enabling unstable features.
198+ ///
199+ /// See the sources for a complete list of features, and members.
200+ pub mod unstable_api {
201+ /// Unstable functions that take a value `UnstableApi` require
202+ /// the "_unstable_api" feature. This feature controls
203+ /// whether the value has `pub` visibility outside the crate.
204+ #[ cfg( feature = "_unstable_api" ) ]
205+ pub use unstable:: UnstableApi ;
206+
207+ /// This is a a supertrait for traits that are considered to be Unstable.
208+ /// Unstable traits do not provide any semver guarantees.
209+ ///
210+ /// Enabling the `_unsealed_unstable traits` makes this supertrait publicly
211+ /// Visible.
212+ ///
213+ ///
214+ /// Declaring an unstable Api within the crate:
215+ /// ```
216+ /// // Within the crate use `crate::unstable::` .
217+ /// pub trait Foo: crate::unstable::UnstableTrait {
218+ /// fn foo(key: crate::unstable::UnstableApi);
219+ /// }
220+ /// ```
221+ ///
222+ /// Deriving the trait outside the crate (requires feature `_unsealed_unstable_traits`)
223+ /// ```
224+ /// struct Bar;
225+ /// impl unstable_api::UnstableTrait for Bar{}
226+ /// impl Foo for Bar {
227+ /// fn foo(key: unstable_api::UnstableApi) {
228+ /// ...
229+ /// }
230+ /// }
231+ /// ```
232+ ///
233+ ///
234+ /// Calling an implementation of the trait outside the crate (requires feature `_unstable_api`:
235+ /// ```
236+ /// let x: &dyn Foo = ...;
237+ /// x.foo(unstable_api::UnstableApi);
238+ /// ```
239+ #[ cfg( feature = "_unsealed_unstable_traits" ) ]
240+ pub use unstable:: UnstableTrait ;
241+
242+ /// An value that acts as a key to inform callers that they are
243+ /// calling an unstable internal api. This value is public by default.
244+ /// Access to it does not require any features to be enabled.
245+ ///
246+ /// Q. When this should be used?
247+ ///
248+ /// A. When generated code needs to call internal api within it,
249+ /// where you do not want the caller to have to enable any features
250+ /// to use the generated code.
251+ pub struct InternalPublicApi ;
252+ }
0 commit comments