Skip to content

create enum-like const-types, but with aliases for variants

Notifications You must be signed in to change notification settings

sivizius/const_type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

create enum-like const-types, but with aliases for variants

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages