1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Provides a marker trait to prevent external implementation of trait methods.
/// A marker trait used to prevent specific already auto-implemented trait methods from being
/// re-implemented outside their defining crate.
///
/// This is achieved by adding this non-referenceable marker trait to a trait method signature.
///
/// # Example
///
/// The following code demonstrates how `Final` prevents external implementation:
///
/// ```ignore
/// pub trait Trait {
/// // This method cannot be implemented by users because it requires
/// // the private `Final` trait in its bounds
/// fn unimplementable(&self) where Self: Final {
/// self.user_impl_this();
/// }
///
/// // This method can be implemented by users
/// fn user_impl_this(&self);
/// }
///
/// pub struct MyType;
///
/// impl Trait for MyType {
/// // Attempting to implement this method will fail to compile
/// // because `Final` is not accessible from outside the crate
/// fn unimplementable(&self) where Self: Final {}
///
/// fn user_impl_this(&self) {
/// println!("This implementation is allowed");
/// }
/// }
/// ```