Crates.io | digenum |
lib.rs | digenum |
version | 0.1.1 |
source | src |
created_at | 2022-11-19 22:30:23.942354 |
updated_at | 2022-11-19 22:43:17.655197 |
description | An enum variant extractor |
homepage | |
repository | https://github.com/Defmc/digenum |
max_upload_size | |
id | 718736 |
size | 5,247 |
Can extract a (mutable) reference or turn into a tuple from fields. When variant is different than the expected, return None
.
use digenum::DigEnum;
use std::io::Read;
#[derive(DigEnum)]
enum Login<T: Read> {
Local,
Stream(T)
Token([u8; 64]),
UserAndPasswd(String, String),
}
Maps to:
Variant | Reference | Mutable Reference | Owned |
---|---|---|---|
Local |
None | None | None |
Stream(T) |
as_Stream -> Option<&T> |
as_mut_Stream -> Option<&mut T> |
into_Stream -> Option<T> |
Token([u8; 64]) |
as_Token -> Option<&[u8; 64]> |
as_mut_Token -> Option<&mut [u8; 64]> |
into_Token -> Option<[u8; 64]> |
UserAndPasswd(String, String) |
as_UserAndPasswd -> Option<(&String, &String)> |
as_mut_UserAndPasswd -> Option<(&mut String, &mut String)> |
into_UserAndPasswd -> Option<(String, String)> |
snake_case
?"Consider this example:
use digenum::DigEnum;
#[derive(DigEnum)]
enum Foo {
FOO,
foo,
Foo
}
How should I handle it?
Foo::FOO
and Foo::foo
)