#[sealed]
This crate provides a convenient and simple way to implement the sealed trait pattern, as described in the Rust API Guidelines [1].
[]
= "0.1"
Example
In the following code structs A
and B
implement the sealed trait T
,
the C
struct, which is not sealed, will error during compilation.
You can see a demo in demo/
.
use sealed;
;
;
;
// compile error
Details
The macro generates a private
module when attached to a trait
(this raises the limitation that the #[sealed]
macro can only be added to a single trait per module),
when attached to a struct
the generated code simply implements the sealed trait for the respective structure.
Expansion
// #[sealed]
// trait T {}
// #[sealed]
// pub struct A;
;