[−][src]Trait structural::field::rev_get_field::RevIntoFieldRef
A trait alias for infallible RevIntoFieldImpl
+ RevGetFieldImpl
,
generally used to access fields in structs(not in a nested enum inside the struct).
This
is the type we are accessing,and Self
is a field path.
Example
This example shows how to access a struct field by reference,and by value.
Also,how to write extension traits with Rev*
traits.
use structural::field::{RevIntoFieldRef,RevGetFieldType}; use structural::for_examples::StructBar; use structural::{StructuralExt,FP,fp}; let foo=StructBar{ bar: ([(0,3),(5,8)], [(40,50,60)]), }; assert_eq!( foo.get_nested(), &(5,8) ); assert_eq!( foo.into_nested(), (5,8) ); let oop=StructBar{ bar: [["hello","world"],["uh","no"]], }; assert_eq!( oop.get_nested(), &"world" ); assert_eq!( oop.into_nested(), "world" ); trait GetNested: Sized { fn get_nested<'a,Ty>(&'a self)->&'a Ty where FP!(bar.0.1): RevIntoFieldRef<'a,Self,Ty=Ty> { self.field_(fp!(bar.0.1)) } fn into_nested<'a,Ty>(self)->Ty where FP!(bar.0.1): RevIntoFieldRef<'a,Self,Ty=Ty> { self.into_field(fp!(bar.0.1)) } } impl<T> GetNested for T {}
Implementors
impl<'a, Path, This> RevIntoFieldRef<'a, This> for Path where
Path: RevIntoField<This> + RevGetFieldMut<'a, This>,
[src]
Path: RevIntoField<This> + RevGetFieldMut<'a, This>,