fnum

Fnum is an utility trait for enum, that provides size_of_variant method. size_of_variant returns the minimum size that specified variant requiring.

Usage

``` rust use fnum::Fnum;

[derive(Fnum)]

enum MyEnum { A(u64), B(String), C(u64, u32, u32, u32), D { foo: u32, bar: String, } }

fn main() { dbg!(MyEnum::sizeofvariant(0)); // => 16 (bytes required by MyEnum::A(..)) dbg!(MyEnum::sizeofvariant(1)); // => 32 (bytes required by MyEnum::B(..)) dbg!(MyEnum::sizeofvariant(2)); // => 24 (bytes required by MyEnum::C(..)) dbg!(MyEnum::sizeofvariant(3)); // => 32 (bytes required by MyEnum::D{..}) } ```

Author

Copyright

Copyright (c) 2020 carrotflakes (carrotflakes@gmail.com)

License

Licensed under the MIT License.