[][src]Trait structural::field::rev_get_field::OptRevIntoFieldMut

pub trait OptRevIntoFieldMut<'a, This>: OptRevIntoField<This> + OptRevGetFieldMut<'a, This> { }

A trait alias for fallible RevIntoFieldImpl + RevGetFieldMutImpl, 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 mutable reference,and by value.

Also,how to write extension traits with Rev* traits.

use structural::field::{OptRevIntoFieldMut,RevGetFieldType};
use structural::for_examples::{StructFoo,WithBoom};
use structural::{StructuralExt,FP,fp};

let mut nope=StructFoo{ foo: WithBoom::Nope };
let mut boom=StructFoo{ foo: WithBoom::Boom{  a: "hello", b: &[3,5,8,13]  } };

assert_eq!( nope.get_nested_mut(), None );
assert_eq!( boom.get_nested_mut(), Some(&mut &[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_mut<'a,Ty>(&'a mut self)->Option<&'a mut Ty>
    where
        FP!(foo::Boom.b): OptRevIntoFieldMut<'a,Self,Ty=Ty>
    {
        self.field_mut(fp!(foo::Boom.b))
    }

    fn into_nested<'a,Ty>(self)->Option<Ty>
    where
        FP!(foo::Boom.b): OptRevIntoFieldMut<'a,Self,Ty=Ty>
    {
        self.into_field(fp!(foo::Boom.b))
    }
}

impl<T> GetNested for T {}

Implementors

impl<'a, Path, This> OptRevIntoFieldMut<'a, This> for Path where
    Path: OptRevIntoField<This> + OptRevGetFieldMut<'a, This>, 
[src]

Loading content...