pair_macro
Create types consisting of the same type values such that Pair, Triplet, and so on.
This crate runs on no-std
environment.
Examples
Use a provided type Pair<T>
.
use Pair;
let p = new; // Pair<f64>
let q = p.map;
assert_eq!;
// `Pair<T>` has `x` and `y` fields
assert_eq!;
assert_eq!;
Create a new pair type.
use *;
create_pair!;
let p = new; // MyOwnPair<i32>
let q = new;
let r = p + q;
// `MyOwnPair<T>` has `a`, `b`, `c` and `d` fields
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Use provided methods
use FromStr;
use Pair;
let p = new; // Pair<[&str; 2]>
let value = p
.as_ref // Pair<&[&str; 2]>
.map // Pair<&str>
.map // Pair<Result<i32, Error>>
.into_result // Result<Pair<i32>, Error>
.unwrap // Pair<i32>
.into_iter // Iterates each value in the pair (`42` and `58` in this situation)
.; // 42 + 58
assert_eq!;
Of course, your original pair types defined by create_pair!
macro have the same methods.
Features
Pair types support serde by enabling serde
feature: in your Cargo.toml
,
pair_macro = { version = "0.1.4", features = ["serde"] }
Note
Pair types' documentation may be slightly hard to read since it is generated by macro expansion.
License: MIT