pub trait RevIntoMultiField<This>: RevIntoMultiFieldImpl<This> {
type IntoFields;
// Required method
fn rev_into_multi_field(self, this: This) -> Self::IntoFields;
}Expand description
Converts This into multiple fields by value.
This trait has a blanket implementation for the RevIntoMultiFieldImpl trait,
implementing that trait is necessary to be able to use this trait.
This is used by the
StructuralExt::into_fields
method.
There’s also the RevIntoMultiFieldOut type alias to get this trait’s
IntoFields associated type.
§Example
This demonstrates how you can use RevIntoMultiField with structs.
use structural::{
field::RevIntoMultiField,
for_examples::{Tuple3, Tuple4},
FP, StructuralExt, fp,
};
assert_eq!(into_pair((13,21,34)), (13,21));
assert_eq!(into_pair(('a','b','c','d','e')), ('a','b'));
assert_eq!(into_pair(Tuple3(Some(3),5,8)), (Some(3),5));
assert_eq!(into_pair(Tuple4(Some("foo"),"bar","baz","qux")), (Some("foo"),"bar"));
fn into_pair<A,B,T>(this: T)->(A,B)
where
FP!(0,1): RevIntoMultiField<T,IntoFields= (A,B)>,
{
this.into_fields(fp!(0,1))
}
§Example
This demonstrates how you can use RevIntoMultiField with enums.
use structural::{
field::RevIntoMultiField,
for_examples::{Bomb, WithBoom},
FP, StructuralExt, fp,
};
let with_0 = WithBoom::Nope;
let with_1 = WithBoom::Boom{a:"hi", b: &[0,1,2]};
assert_eq!( into_pair(with_0), None );
assert_eq!( into_pair(with_1), Some(("hi", &[0,1,2][..])) );
let bomb_0 = Bomb::Nope;
let bomb_1 = Bomb::Boom{a:"hello", b: &[5,8,13]};
assert_eq!( into_pair(bomb_0), None );
assert_eq!( into_pair(bomb_1), Some(("hello", &[5,8,13][..])) );
fn into_pair<A,B,T>(this: T)->Option<(A,B)>
where
FP!(::Boom=>a,b): RevIntoMultiField<T,IntoFields= Option<(A,B)>>,
{
this.into_fields(fp!(::Boom=>a,b))
}
Required Associated Types§
Sourcetype IntoFields
type IntoFields
This is usually a tuple of Option<T>s and Ts.
Required Methods§
Sourcefn rev_into_multi_field(self, this: This) -> Self::IntoFields
fn rev_into_multi_field(self, this: This) -> Self::IntoFields
Converts this into multiple fields by value.
usually a tuple of Option<T>s and Ts.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.