#[sealed]

This crate provides a convenient and simple way to implement the sealed trait pattern, as described in the Rust API Guidelines [1].

toml [dependencies] sealed = "0.3"

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.

Examples are available in examples/, you can also see a demo in demo/.

```rust use sealed::sealed;

[sealed]

trait T {}

pub struct A;

[sealed]

impl T for A {}

pub struct B;

[sealed]

impl T for B {}

pub struct C;

impl T for C {} // compile error ```

Arguments

This is the list of arguments that can be used in a #[sealed] attribute:

Details

The #[sealed] attribute can be attached to either a trait or an impl. It supports: - Several traits per module - Generic parameters - Foreign types - Blanket impls

Expansion

Input

```rust use sealed::sealed;

pub struct A; pub struct B(i32);

[sealed]

pub trait T {}

[sealed]

impl T for A {}

[sealed]

impl T for B {} ```

Expanded

```rust use sealed::sealed;

pub struct A; pub struct B(i32);

mod _sealt { pub trait Sealed {} } pub trait T: _sealt::Sealed {}

impl _sealt::Sealed for A {} impl T for A {}

impl _sealt::Sealed for B {} impl T for B {} ```