#enums #variant #cast #encapsulation #macro-derive

enumcapsulate

Safe casting for newtype enums and their variants

2 unstable releases

0.2.0 Mar 21, 2024
0.1.0 Jan 22, 2024

#1048 in Rust patterns

Download history 4/week @ 2024-01-19 4/week @ 2024-02-16 21/week @ 2024-02-23 4/week @ 2024-03-01 68/week @ 2024-03-15 52/week @ 2024-03-22 33/week @ 2024-03-29 9/week @ 2024-04-05

162 downloads per month

MPL-2.0 license

22KB
73 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

~125KB