[][src]Trait structural::field_traits::GetFieldExt

pub trait GetFieldExt {
    fn field_<FieldName>(&self, _: FieldName) -> &Self::Ty
    where
        Self: GetField<FieldName>
, { ... }
fn fields<'a, Fields>(&'a self, _: TStringSet<Fields>) -> Fields::MultiTy
    where
        Fields: GetMultiField<'a, Self>
, { ... }
fn field_mut<FieldName>(&mut self, _: FieldName) -> &mut Self::Ty
    where
        Self: GetFieldMut<FieldName>
, { ... }
fn fields_mut<'a, Fields>(
        &'a mut self,
        ms: TStringSet<Fields>
    ) -> Fields::MultiTy
    where
        Fields: GetMultiFieldMut<'a, Self>,
        Self: Sized
, { ... }
fn into_field<FieldName>(self, _: FieldName) -> Self::Ty
    where
        Self: IntoField<FieldName> + Sized
, { ... }
fn box_into_field<FieldName>(self: Box<Self>, _: FieldName) -> Self::Ty
    where
        Self: IntoField<FieldName>
, { ... } }

An extension trait,which defines methods for accessing fields generically.

Provided methods

fn field_<FieldName>(&self, _: FieldName) -> &Self::Ty where
    Self: GetField<FieldName>, 

Gets a reference to the ´FieldName´ field.

This is named field_ instead of field because field collides with the DebugTuple/DebugStruct method

Example

use structural::{GetFieldExt,ti};

let tup=(1,1,2,3,5,8);

assert_eq!( tup.field_(ti!(0)), &1 );
assert_eq!( tup.field_(ti!(1)), &1 );
assert_eq!( tup.field_(ti!(2)), &2 );
assert_eq!( tup.field_(ti!(3)), &3 );
assert_eq!( tup.field_(ti!(4)), &5 );
assert_eq!( tup.field_(ti!(5)), &8 );

fn fields<'a, Fields>(&'a self, _: TStringSet<Fields>) -> Fields::MultiTy where
    Fields: GetMultiField<'a, Self>, 

Gets multiple references to fields.

Example

use structural::{GetFieldExt,ti};

let tup=(1,1,2,3,5,8);

assert_eq!( tup.fields(ti!(0,1)),  (&1,&1) );
assert_eq!( tup.fields(ti!(3,2)),  (&3,&2) );
assert_eq!( tup.fields(ti!(4,5,3)),(&5,&8,&3) );

fn field_mut<FieldName>(&mut self, _: FieldName) -> &mut Self::Ty where
    Self: GetFieldMut<FieldName>, 

Gets a mutable reference to the ´FieldName´ field.

Example

use structural::{GetFieldExt,ti};

let mut tup=(1,1,2,3,5,8);

assert_eq!( tup.field_mut(ti!(0)), &mut 1 );
assert_eq!( tup.field_mut(ti!(1)), &mut 1 );
assert_eq!( tup.field_mut(ti!(2)), &mut 2 );
assert_eq!( tup.field_mut(ti!(3)), &mut 3 );
assert_eq!( tup.field_mut(ti!(4)), &mut 5 );
assert_eq!( tup.field_mut(ti!(5)), &mut 8 );

fn fields_mut<'a, Fields>(
    &'a mut self,
    ms: TStringSet<Fields>
) -> Fields::MultiTy where
    Fields: GetMultiFieldMut<'a, Self>,
    Self: Sized

Gets multiple mutable references to fields.

This is safe since TStringSet requires its strings to be checked for uniqueness before being constructed (the safety invariant of TStringSet).

Example

use structural::{GetFieldExt,ti};

let mut tup=(1,1,2,3,5,8);

assert_eq!( tup.fields_mut(ti!(0,1)), (&mut 1,&mut 1) );
assert_eq!( tup.fields_mut(ti!(3,2)), (&mut 3,&mut 2) );
assert_eq!( tup.fields_mut(ti!(4,5,3)), (&mut 5,&mut 8,&mut 3) );

fn into_field<FieldName>(self, _: FieldName) -> Self::Ty where
    Self: IntoField<FieldName> + Sized

Converts ´self´ into the ´FieldName´ field.

Example

use structural::{GetFieldExt,ti};

let tup=(1,1,2,3,5,8);

assert_eq!( tup.clone().into_field(ti!(0)), 1 );
assert_eq!( tup.clone().into_field(ti!(1)), 1 );
assert_eq!( tup.clone().into_field(ti!(2)), 2 );
assert_eq!( tup.clone().into_field(ti!(3)), 3 );
assert_eq!( tup.clone().into_field(ti!(4)), 5 );
assert_eq!( tup.clone().into_field(ti!(5)), 8 );

fn box_into_field<FieldName>(self: Box<Self>, _: FieldName) -> Self::Ty where
    Self: IntoField<FieldName>, 

Converts a boxed ´self´ into the ´FieldName´ field.

Example

use structural::{GetFieldExt,ti};

let tup=Box::new((1,1,2,3,5,8));

assert_eq!( tup.clone().box_into_field(ti!(0)), 1 );
assert_eq!( tup.clone().box_into_field(ti!(1)), 1 );
assert_eq!( tup.clone().box_into_field(ti!(2)), 2 );
assert_eq!( tup.clone().box_into_field(ti!(3)), 3 );
assert_eq!( tup.clone().box_into_field(ti!(4)), 5 );
assert_eq!( tup.clone().box_into_field(ti!(5)), 8 );
Loading content...

Implementors

impl<T: ?Sized> GetFieldExt for T[src]

Loading content...