const_type 0.1.3

define enum-like const-types, but with aliases for variants
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 4.03 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 239.39 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sivizius/const_type
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sivizius

const_type

Define enum-like const-types, but with aliases for variants:

  use const_type::
  {
    Const,
  };

  Const!
  {
    /// `Bar` is like enum, but variants might have the same value.
    /// `usize` is the default type, so `: usize` can be omitted in this case.
    pub Bar: usize
    {
      /// Even Variants could be and should be documented.
      A = 1,
      B = 2,
      C = 2,
      D = Bar::A.0,
    }
  }

This could be used like this:

  let Foo: Bar = Bar::B;

Because the enum is actually a struct, implementing traits or methods canbe doneas usually:

impl Into < usize > for Bar
{
  fn into
  (
    self
  )
  ->  usize
  {
    self.0 as usize
  }
}