pub trait IntoFieldMut<F>: IntoField<F> + GetFieldMut<F> { }
Expand description
A bound for shared, mutable,and by-value access to the FieldName
field.
This is only usable as a bound, to access the field you can use any StructuralExt method.
§Example
This particular example only works with the “alloc” feature enabled
(it’s enabled by default),because it uses Box
.
use structural::{StructuralExt,IntoFieldMut,FP,fp};
use structural::for_examples::{Struct2,Struct3};
fn example(mut this:Box<dyn Bounds>){
assert_eq!( this.field_(fp!(foo)), &Some(false) );
assert_eq!( this.field_(fp!(bar)), &"oh boy" );
assert_eq!( this.fields(fp!(foo,bar)), (&Some(false), &"oh boy") );
assert_eq!( this.cloned_fields(fp!(foo,bar)), (Some(false), "oh boy") );
assert_eq!( this.field_mut(fp!(foo)), &mut Some(false) );
assert_eq!( this.field_mut(fp!(bar)), &mut "oh boy" );
assert_eq!( this.fields_mut(fp!(foo,bar)), (&mut Some(false), &mut "oh boy") );
assert_eq!( this.into_fields(fp!(foo, bar)), (Some(false), "oh boy") );
}
example(Box::new(Struct2{ foo:Some(false), bar: "oh boy" }));
example(Box::new(Struct3{ foo:Some(false), bar: "oh boy", baz:5 }));
// This trait and impl block is what the `structural_alias` macro expands to.
trait Bounds:
IntoFieldMut<FP!(foo), Ty=Option<bool>> +
IntoFieldMut<FP!(bar), Ty=&'static str>
{}
impl<This> Bounds for This
where
This:?Sized +
IntoFieldMut<FP!(foo), Ty=Option<bool>> +
IntoFieldMut<FP!(bar), Ty=&'static str>
{}