sealed_trait

Crates.iosealed_trait
lib.rssealed_trait
version0.1.1
created_at2025-02-20 12:26:43.191706+00
updated_at2025-02-20 12:53:28.452164+00
descriptionA utility for making sealed traits more accessible
homepage
repositoryhttps://github.com/SunkenPotato/sealed_trait
max_upload_size
id1562587
size5,423
SunkenPotato (SunkenPotato)

documentation

README

sealed_trait

A utility for generating sealed traits in Rust. Inspired by Java's sealed class syntax.

Usage

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 => {
        ...
    }
}
Commit count: 10

cargo fmt