docs.rs failed to build seoul-0.3.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
seoul-1.0.0
Seoul-Rs
- derive trait Isomorphism for Enum data
- derive trait Tuplike for Struct data
- derive trait Reflica for Struct and Enum 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>;
-
The derive macro also implements
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
Tuplikehas an associated typeTuple. With the derive macro, the tuple format will be assigned for it.
Example
use Tuplike;
let tuple_: = ;
let ab_: AB = AB ;
let _: Tuple = ab_.clone.into;
let ab_into: = ab_.clone.into;
let tuple_into: AB = tuple_.clone.into;
assert_eq!;
assert_eq!;
let _ab_ref_into: = .into;
Trait Reflica
-
Declare a borrowed fields' data type ("reflica") from an original struct/enum data type, and implement Into trait to the reflica.
-
concept of reflica:
struct AB { a: u8, b: String }- declare
struct RefAB<'a> { a: &'a u8, b: &'a String } - implement
Into<RefAB<'a>> for &'a AB
- declare
-
enum AB { A, B { a: u8, b: String } }- declare
enum RefAB<'a> { A, B { a: &'a u8, b: &'a String } } - implement
Into<RefAB<'a>> for &'a AB
- declare
Example
use Reflica;
// struct
// attribute for derive implementation for the reflica
// RefAB delcared
let _: = RefAB ;
// check Into<RefAB> for &AB
let x = AB ;
let _: = .into;
// check derive `Ord`
let a: = RefAB ;
let b: = RefAB ;
let c: = RefAB ;
let x = vec!;
let mut y = x.clone;
y.sort;
assert_eq!;
// enum, use prefix other than basic `Ref`
// `prefix` attribute's string value will be used for reflica's prefix, other than the basic prefix `Ref`
// Ref2AB delcared
let _: = A;
let _: = B ;
// check Into<Ref2AB>
let x = ABCB ;
let _: = .into;
let x = ABC::C;
let _: = .into;
Dev Log
- ver.0.2.0
- `From<T>` implemented only with `has_default` attribute syntax when `Default` is implemented.
- ver 0.2.1~2
- correct some typos
- ver 0.3.0
- Add `Tuplike`.
- ver 0.3.1
- Add an associated type `Tuple` to the trait `Tuplike`
- ver 0.3.2
- Add `Reflica`