pub trait OptRevIntoFieldRef<'a, This>: OptRevIntoField<This> + OptRevGetFieldMut<'a, This> { }Expand description
A trait alias for fallible RevIntoFieldImpl + 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 to access an enum field by reference,and by value.
Also,how to write extension traits with Rev* traits.
use structural::field::{OptRevIntoFieldRef,RevGetFieldType};
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!( nope.get_nested(), None );
assert_eq!( boom.get_nested(), Some(&&[3,5,8,13][..]) );
assert_eq!( nope.into_nested(), None );
assert_eq!( boom.into_nested(), Some(&[3,5,8,13][..]) );
trait GetNested: Sized {
fn get_nested<'a,Ty>(&'a self)->Option<&'a Ty>
where
FP!(foo::Boom.b): OptRevIntoFieldRef<'a,Self,Ty=Ty>
{
self.field_(fp!(foo::Boom.b))
}
fn into_nested<'a,Ty>(self)->Option<Ty>
where
FP!(foo::Boom.b): OptRevIntoFieldRef<'a,Self,Ty=Ty>
{
self.into_field(fp!(foo::Boom.b))
}
}
impl<T> GetNested for T {}
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.