Seoul-Rs
- derive trait Isomorphism for Enum data
- derive trait Tuplike for Struct data
Trait Isomorphism
-
for 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!;
Trait Tuplike
-
for struct data type. Transform a struct data into tuple format
AB { a: 0, b: 10 }<=>(0, 10)
-
Using derive macro, you can implement
- trait
From<T>forSelf - trait
Into<T>forSelf - trait
Into<R>forSelf - Hereby,
Tis a tuple format of the struct's fields, - and the
Ris a referenced tuple format of them.
- trait
-
The trait
Tuplikeitself doesn't have own methods.
Example
use Tuplike;
let tuple_: = ;
let ab_: AB = AB ;
let ab_into: = ab_.clone.into;
let tuple_into: AB = tuple_.clone.into;
assert_eq!;
assert_eq!;
let _ab_ref_into: = .into;
Dev Log
-
ver.0.2.0
From<T>implemented only withhas_defaultattribute syntax whenDefaultis implemented.
-
ver 0.2.1~2
- correct some typos
-
ver 0.3.0
- Add
Tuplike.
- Add