Seoul-Rs
Trait Isomorphism
-
To handle enum data type. Convenient transformation of enum values with derive macro.
-
Basic methods:
fn title(&self) -> String;fn list() -> Vec<Self>;
-
Using derive macro, also are implemented
Into<T>forSelfand&SelfFrom<T>andFrom<&T>forSelf(whenDefaultis implemented and "has_default" syntax is given)
derive syntax and fallback
- When title is not given at variant level, the variant's name (Ident) will be used as titile.
- When list is not given at the top level attribute, list of each variant's default format will be returned.
- When into value is not given at variant level, the into type(T)'s default value will be used in
<Into<T>>trait. - When the type implements
Defaultand has_default is given at top level attribute, theFrom<T>andFrom<&T>will be implemented for each given into types(T).
Examples
use Isomorphism;
// `list()`
let list = ABClist;
assert_eq!;
let a: ABC = ABCA;
let b = ABCB;
let c = ABCC;
// `title()`
assert_eq!;
assert_eq!;
assert_eq!;
// `Into<T>` for `&Self` and `Self`
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// list
assert_eq!;
// Into
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// From
assert_eq!;
assert_eq!;
// fallback to default value of `CD`
assert_eq!;
Dev Log
- ver.0.2.0
From<T>implemented only withhas_defaultattribute syntax whenDefaultis implemented.
- ver 0.2.1~2
- correct some typos