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

pub trait RevIntoFieldMut<'a, This>: RevIntoField<This> + RevGetFieldMut<'a, This> { }

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

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

use structural::field::{RevIntoFieldMut,RevGetFieldType};
use structural::for_examples::StructBar;
use structural::{StructuralExt,FP,fp};

let mut foo=StructBar{
    bar: ([(0,3),(5,8)], [(40,50,60)]),
};

assert_eq!( foo.get_nested_mut(), &mut (5,8) );
assert_eq!( foo.into_nested(), (5,8) );

let mut oop=StructBar{
    bar: [["hello","world"],["uh","no"]],
};

assert_eq!( oop.get_nested_mut(), &mut "world" );
assert_eq!( oop.into_nested(), "world" );

trait GetNested: Sized {
    fn get_nested_mut<'a,Ty>(&'a mut self)->&'a mut Ty
    where
        FP!(bar.0.1): RevIntoFieldMut<'a,Self,Ty=Ty>
    {
        self.field_mut(fp!(bar.0.1))
    }

    fn into_nested<'a,Ty>(self)->Ty
    where
        FP!(bar.0.1): RevIntoFieldMut<'a,Self,Ty=Ty>
    {
        self.into_field(fp!(bar.0.1))
    }
}

impl<T> GetNested for T {}

Implementors

impl<'a, Path, This> RevIntoFieldMut<'a, This> for Path where
    Path: RevIntoField<This> + RevGetFieldMut<'a, This>, 
[src]

Loading content...