Derive Macro fields_converter_derive::OrdFields
source · #[derive(OrdFields)]
{
// Attributes available to this derive:
#[destinations]
}
Expand description
A derive macro for PartialOrd
trait.
To automagically derive the trait for your type against a DesiredTypeName
add the
following attributes to it:
#[derive(EqFields, OrdFields)]
,- and
#[destinations("DesiredTypeName")]
.
… and the macro will generate an implementations of PartialEq<DesiredTypeName>
for you type
then. Yes, EqFields
is a prerequisite for OrdFields
, the same as PartialEq
is a
prerequisite for PartialOrd
.
You can add more than one type, like #[destinations("Type1", "Type2", ...)]
.
It is possible to use structs with fields with different types, the only requirement is that
respective types should be comparable with the PartialEq
trait.
#[macro_use(EqFields, OrdFields)]
extern crate fields_converter_derive;
#[derive(Debug)]
struct ExternalType<'a, T> {
field1: String,
field2: T,
field3: &'a str,
}
#[derive(EqFields, OrdFields, Debug)]
#[destinations("ExternalType")]
struct MyType<'a, T: PartialOrd> {
field1: String,
field2: T,
field3: &'a str,
}
fn main() {
let source = ExternalType {
field1: "lol".into(),
field2: 9907,
field3: "testing",
};
let mut my = MyType {
field1: "lol".into(),
field2: 9907,
field3: "testing",
};
assert_eq!(my, source);
assert_eq!(source, my);
assert!(!(my < source));
assert!(!(my > source));
assert!(!(source < my));
assert!(!(source > my));
my.field2 += 1;
assert!(my > source);
assert!(source < my);
my.field1 = "a".into();
assert!(my < source);
assert!(source > my);
}