pub trait OptRevGetField<'a, This>: RevGetFieldImpl<'a, This, Err = FailedAccess> { }Expand description
A trait alias for a fallible RevGetFieldImpl,
generally used to access fields inside enums.
This is the type we are accessing,and Self is a field path.
§Example
This example shows how you can access an enum field by reference.
use structural::field::OptRevGetField;
use structural::{StructuralExt,FP,fp};
let tup1=(3,5,(8,(Some(13),21)));
let tup2=(3,5,(8,(None,21)));
assert_eq!( get_nested(&tup1), Some(&13) );
assert_eq!( get_nested(&tup2), None );
fn get_nested<'a,T>(this:&'a T)->Option<&'a i32>
where
FP!(2.1.0?): OptRevGetField<'a,T,Ty=i32>
{
this.field_(fp!(2.1.0?))
}
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.