#enums #cast #variant

enumcapsulate

Safe casting for newtype enums and their variants

4 releases (2 breaking)

0.3.0 May 24, 2024
0.2.2 May 23, 2024
0.2.0 Mar 21, 2024
0.1.0 Jan 22, 2024

#895 in Rust patterns

MPL-2.0 license

21KB
82 lines

enumcapsulate

Crates.io Crates.io Crates.io docs.rs

Safe casting for newtype enums and their variants.


Traits

The enumcapsulate crate exports the following traits:

Traits Functionality
AsVariant Umbrella derive macro for AsVariantRef, and AsVariantMut
AsVariantMut Used to do a cheap mutable-to-mutable reference conversion between an outer enum's and its inner variant's type
AsVariantRef Used to do a cheap reference-to-reference reference conversion between an outer enum's and its inner variant's type
Encapsulate Umbrella derive macro for AsVariantMut, AsVariantRef, From, FromVariant, IntoVariant, IsVariant, TryInto, VariantDiscriminant, and VariantDowncast AsVariantMut
FromVariant Used to do variant-to-enum conversions between an outer enum's and its inner variant's type
IntoVariant Used to do enum-to-variant conversions between an outer enum's and its inner variant's type
IsVariant Used to check type of an enum's inner variant's type
VariantDiscriminant Used to obtain an enum variant's discriminant
VariantDowncast Convenience umbrella trait utilizing AsVariantRef, AsVariantMut, and IntoVariant

Derive macros

as well as the following corresponding derive macros via enumcapsulate::derive::*:

  • AsVariant
  • AsVariantMut
  • AsVariantRef
  • Encapsulate
  • From
  • FromVariant
  • IntoVariant
  • IsVariant
  • TryInto
  • VariantDiscriminant

Documentation

Please refer to the documentation on docs.rs.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.

Dependencies

~105KB