sealed_trait 0.1.0

A utility for making sealed traits more accessible
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 4.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 150.66 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • SunkenPotato/sealed_trait
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SunkenPotato

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 {
        ...
    }
}