pub trait Tupleize: From<Self::Equivalent> + Into<Self::Equivalent> {
type Equivalent: From<Self>;
// Provided method
fn tupleize(self) -> Self::Equivalent { ... }
}
Expand description
Convert between Tuple
and struct types.
If there are no special requirements then you should use the derive marco.
§Example
use tuplez::{tuple, Tupleize};
#[derive(Tupleize, Debug, PartialEq, Eq)]
struct Person<Meta> {
name: &'static str,
age: u32,
meta: Meta,
}
let john = Person {
name: "John",
age: 21,
meta: vec![9, 8, 7],
};
assert_eq!(john.tupleize(), tuple!("John", 21, vec![9, 8, 7]));
let smith = Person {
name: "Smith",
age: 49,
meta: Some(88.88),
};
assert_eq!(smith, Person::from(tuple!("Smith", 49, Some(88.88))));
Required Associated Types§
sourcetype Equivalent: From<Self>
type Equivalent: From<Self>
The equivalent tuple type with the same number of elements, the same element types, and the same element order as the struct.
Provided Methods§
sourcefn tupleize(self) -> Self::Equivalent
fn tupleize(self) -> Self::Equivalent
Convert from self into a tuple.
Object Safety§
This trait is not object safe.