| Crates.io | sealed_trait |
| lib.rs | sealed_trait |
| version | 0.1.1 |
| created_at | 2025-02-20 12:26:43.191706+00 |
| updated_at | 2025-02-20 12:53:28.452164+00 |
| description | A utility for making sealed traits more accessible |
| homepage | |
| repository | https://github.com/SunkenPotato/sealed_trait |
| max_upload_size | |
| id | 1562587 |
| size | 5,423 |
sealed_traitA utility for generating sealed traits in Rust.
Inspired by Java's sealed class syntax.
You can create a sealed trait by using the sealed_trait macro:
sealed_trait! {
pub sealed trait TestTrait permits i32 => {
fn print_me(self);
}
impl TestTrait for i32 => {
fn print_me(self) {
println!("{self}")
}
}
}
You can also add supertraits to your traits, but they have to be inside square brackets:
sealed_trait! {
pub sealed trait TestTrait: [Sized, Into<u32>] permits i32 => {
...
}
}