pub trait OptRevIntoField<This>: RevIntoFieldImpl<This, Err = FailedAccess> { }Expand description
A trait alias for a fallible RevIntoFieldImpl,
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 value.
use structural::field::OptRevIntoField;
use structural::for_examples::{StructFoo,WithBoom};
use structural::{StructuralExt,FP,fp};
let nope=StructFoo{ foo: WithBoom::Nope };
let boom=StructFoo{ foo: WithBoom::Boom{ a: "hello", b: &[3,5,8,13] } };
assert_eq!( get_nested(nope), None );
assert_eq!( get_nested(boom), Some(&[3,5,8,13][..]) );
fn get_nested<T>(this:T)->Option<&'static [u16]>
where
FP!(foo::Boom.b): OptRevIntoField<T,Ty=&'static [u16]>
{
this.into_field(fp!(foo::Boom.b))
}
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.