Create types consisting of the same type values such that Pair, Triplet, and so on.
This crate runs on no-std
environment.
Pair<T>
.```rust use pair_macro::Pair;
let p = Pair::new(1.0, 2.0); // Pair
assert_eq!(Pair::new(2.0, 4.0), q);
// Pair<T>
has x
and y
fields
asserteq!(2.0, q.x);
asserteq!(4.0, q.y);
```
```rust use pairmacro::createpair_prelude::*;
create_pair!(MyOwnPair; a, b, c, d);
let p = MyOwnPair::new(1, 2, 3, 4); // MyOwnPair
// MyOwnPair<T>
has a
, b
, c
and d
fields
asserteq!(6, r.a);
asserteq!(8, r.b);
asserteq!(10, r.c);
asserteq!(12, r.d);
```
```rust use core::str::FromStr; use pair_macro::Pair;
let p = Pair::new(["hello", "42"], ["world", "58"]); // Pair<[&str; 2]>
let value = p
.asref() // Pair<&[&str; 2]>
.map(|strs| strs[1]) // Pair<&str>
.map(i32::fromstr) // Pair42
and 58
in this situation)
.sum::
assert_eq!(100, value); ```
Of course, your original pair types defined by create_pair!
macro have the same methods.
Pair types support serde by enabling serde
feature: in your Cargo.toml
,
pair_macro = { version = "0.1.3", features = ["serde"] }
Pair types' documentation may be slightly hard to read since it is generated by macro expansion.
License: MIT