[][src]Struct structural::VariantField

pub struct VariantField<V, F> {
    pub variant: V,
    pub field: F,
}

This allows accessing the F field inside the V enum variant.

This is the type that fp!(::Foo.bar) constructs.

Both the V and F type parameters are TStr.

Construction

You can construct this using (not an exhaustive list):

  • The fp macro, with fp!(::Foo.bar)

  • The VariantField{variant,field} struct literal

  • The new constructor.

  • The NEW associated constant,if both V and F implement core_extensions::ConstDefault (reexported in structural::reexports::ConstDefault).

Example

use structural::{StructuralExt, fp, ts};
use structural::for_examples::Variants;
use structural::path::VariantField;

let mut foo=Variants::Foo(3,5);

assert_eq!( foo.field_(fp!(::Foo.0)), Some(&3) );
assert_eq!( foo.field_(fp!(::Foo.1)), Some(&5) );
assert_eq!( foo.field_(fp!(::Boom.a)), None );
assert_eq!( foo.field_(fp!(::Boom.b)), None );
 
assert_eq!( foo.field_(VariantField::new(ts!(Foo), ts!(0))), Some(&3) );
assert_eq!( foo.field_(VariantField::new(ts!(Foo), ts!(1))), Some(&5) );
assert_eq!( foo.field_(VariantField::new(ts!(Boom), ts!(a))), None );
assert_eq!( foo.field_(VariantField::new(ts!(Boom), ts!(b))), None );


assert_eq!( foo.field_mut(fp!(::Foo.0)), Some(&mut 3) );
assert_eq!( foo.field_mut(fp!(::Foo.1)), Some(&mut 5) );
assert_eq!( foo.field_mut(fp!(::Boom.a)), None );
assert_eq!( foo.field_mut(fp!(::Boom.b)), None );
 
assert_eq!( foo.field_mut(VariantField::new(ts!(Foo), ts!(0))), Some(&mut 3) );
assert_eq!( foo.field_mut(VariantField::new(ts!(Foo), ts!(1))), Some(&mut 5) );
assert_eq!( foo.field_mut(VariantField::new(ts!(Boom), ts!(a))), None );
assert_eq!( foo.field_mut(VariantField::new(ts!(Boom), ts!(b))), None );

Fields

variant: V

The variant this accesses.

field: F

The field this accesses inside the variant.

Implementations

impl<V, F> VariantField<V, F> where
    V: ConstDefault,
    F: ConstDefault
[src]

pub const NEW: Self[src]

Constructs a VariantField<V,F>

impl<V, F> VariantField<V, F>[src]

pub const fn into_path(self) -> NestedFieldPath<(Self,)>[src]

Constructs a NestedFieldPath from this.

pub const fn into_set(self) -> FieldPathSet<(Self,), UniquePaths>[src]

Constructs a FieldPathSet from this.

impl<V, F> VariantField<V, F>[src]

pub const fn new(variant: V, field: F) -> Self[src]

Constructs a VariantField from the name of the variant,and field.

Both name and field is expected to be a ::structural::path::TStr.

Trait Implementations

impl<V: Clone, F: Clone> Clone for VariantField<V, F>[src]

impl<V, F> ConstDefault for VariantField<V, F> where
    V: ConstDefault,
    F: ConstDefault
[src]

impl<V: Copy, F: Copy> Copy for VariantField<V, F>[src]

impl<T, U> Debug for VariantField<T, U>[src]

impl<V, F> Eq for VariantField<V, F>[src]

impl<T, E> FieldType<VariantField<TStr<__TS<(__E, __r, __r)>>, TStr<__TS<(__0,)>>>> for Result<T, E>[src]

type Ty = E

The type of the FieldPath field.

impl<T, E> FieldType<VariantField<TStr<__TS<(__O, __k)>>, TStr<__TS<(__0,)>>>> for Result<T, E>[src]

type Ty = T

The type of the FieldPath field.

impl<T> FieldType<VariantField<TStr<__TS<(__S, __o, __m, __e)>>, TStr<__TS<(__0,)>>>> for Option<T>[src]

type Ty = T

The type of the FieldPath field.

impl<V, F> IsMultiFieldPath for VariantField<V, F>[src]

type PathUniqueness = UniquePaths

Whether the paths in the set can contain duplicate paths. Read more

impl<V, F> IsSingleFieldPath for VariantField<V, F>[src]

impl<V, F> Ord for VariantField<V, F>[src]

impl<V, F> PartialEq<VariantField<V, F>> for VariantField<V, F>[src]

impl<V, F> PartialOrd<VariantField<V, F>> for VariantField<V, F>[src]

impl<This: ?Sized, _V, _F> RevFieldErr<This> for VariantField<_V, _F> where
    This: FieldType<Self>, 
[src]

type Err = FailedAccess

The error returned by rev_* methods. Read more

impl<This: ?Sized, _V, _F> RevFieldType<This> for VariantField<_V, _F> where
    This: FieldType<Self>, 
[src]

type Ty = GetFieldType<This, Self>

The type of the field.

impl<'a, This: ?Sized, _V, _F> RevGetFieldImpl<'a, This> for VariantField<_V, _F> where
    This: 'a + GetVariantField<_V, _F>,
    This::Ty: 'a, 
[src]

impl<'a, This: ?Sized, _V, _F> RevGetFieldMutImpl<'a, This> for VariantField<_V, _F> where
    This: 'a + GetVariantFieldMut<_V, _F>,
    This::Ty: 'a, 
[src]

impl<'a, This: ?Sized, V, F> RevGetMultiFieldImpl<'a, This> for VariantField<V, F> where
    Self: RevGetFieldImpl<'a, This>,
    This: 'a,
    RGFT<Self, This>: 'a,
    Result<&'a RGFT<Self, This>, RGFE<Self, This>>: 'a + NormalizeFields
[src]

type UnnormFields = (Result<&'a RGFT<Self, This>, RGFE<Self, This>>,)

A collection of Results<&'a _,_>s referencing fields.

impl<'a, This: ?Sized, V, F> RevGetMultiFieldMutImpl<'a, This> for VariantField<V, F> where
    Self: RevGetFieldMutImpl<'a, This>,
    This: 'a,
    RGFT<Self, This>: 'a,
    Result<&'a mut RGFT<Self, This>, RGFE<Self, This>>: NormalizeFields,
    Result<*mut RGFT<Self, This>, RGFE<Self, This>>: NormalizeFields
[src]

type UnnormFieldsMut = (Result<&'a mut RGFT<Self, This>, RGFE<Self, This>>,)

This is usually a tuple of Result<&mut _,E: IsFieldErr>s.

type UnnormFieldsRawMut = (Result<*mut RGFT<Self, This>, RGFE<Self, This>>,)

This is usually a tuple of Result<*mut _,E: IsFieldErr>s.

impl<This: ?Sized, _V, _F> RevIntoFieldImpl<This> for VariantField<_V, _F> where
    This: IntoVariantField<_V, _F>, 
[src]

impl<This, V, F> RevIntoMultiFieldImpl<This> for VariantField<V, F> where
    Self: RevIntoFieldImpl<This>,
    RGFT<Self, This>: Sized,
    Result<RGFT<Self, This>, RGFE<Self, This>>: NormalizeFields
[src]

type UnnormIntoFields = (Result<RGFT<Self, This>, RGFE<Self, This>>,)

This is usually a tuple of Result<_, E: IsFieldErr>s.

impl<This: ?Sized, _V, _F> RevMoveOutFieldImpl<This> for VariantField<_V, _F> where
    This: IntoVariantField<_V, _F>, 
[src]

impl<V, F> ShallowFieldPath for VariantField<V, F>[src]

Auto Trait Implementations

impl<V, F> RefUnwindSafe for VariantField<V, F> where
    F: RefUnwindSafe,
    V: RefUnwindSafe

impl<V, F> Send for VariantField<V, F> where
    F: Send,
    V: Send

impl<V, F> Sync for VariantField<V, F> where
    F: Sync,
    V: Sync

impl<V, F> Unpin for VariantField<V, F> where
    F: Unpin,
    V: Unpin

impl<V, F> UnwindSafe for VariantField<V, F> where
    F: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<This, T> Array0<T> for This where
    This: ?Sized
[src]

impl<This, V, T> Array0Variant<T, V> for This where
    This: ?Sized
[src]

impl<This, T> ArrayMove0<T> for This where
    This: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<This, T> IntoStructural<T> for This where
    T: FromStructural<This>, 
[src]

impl<'a, Path, This> OptRevGetField<'a, This> for Path where
    Path: RevGetFieldImpl<'a, This, Err = FailedAccess>, 
[src]

impl<'a, Path, This> OptRevGetFieldMut<'a, This> for Path where
    Path: RevGetFieldMutImpl<'a, This, Err = FailedAccess>, 
[src]

impl<Path, This> OptRevIntoField<This> for Path where
    Path: RevIntoFieldImpl<This, Err = FailedAccess>, 
[src]

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

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

impl<'a, This, Path> RevGetMultiField<'a, This> for Path where
    Path: RevGetMultiFieldImpl<'a, This>,
    This: 'a + ?Sized
[src]

type Fields = <<Path as RevGetMultiFieldImpl<'a, This>>::UnnormFields as NormalizeFields>::Output

This is usually a tuple of Option<&_>s and &_s.

impl<'a, This, Path> RevGetMultiFieldMut<'a, This> for Path where
    Path: RevGetMultiFieldMutImpl<'a, This>,
    This: 'a + ?Sized
[src]

type FieldsMut = <<Path as RevGetMultiFieldMutImpl<'a, This>>::UnnormFieldsMut as NormalizeFields>::Output

This is usually a tuple of Option<&mut _>s and &mut _s.

type FieldsRawMut = <<Path as RevGetMultiFieldMutImpl<'a, This>>::UnnormFieldsRawMut as NormalizeFields>::Output

This is usually a tuple of Option<*mut _>s and *mut _s.

impl<This, Path> RevIntoMultiField<This> for Path where
    Path: RevIntoMultiFieldImpl<This>, 
[src]

type IntoFields = <<Path as RevIntoMultiFieldImpl<This>>::UnnormIntoFields as NormalizeFields>::Output

This is usually a tuple of Option<T>s and Ts.

impl<T> SelfOps for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The error type returned when the conversion fails.

impl<This, T> TryIntoStructural<T> for This where
    T: TryFromStructural<This>, 
[src]

type Error = <T as TryFromStructural<This>>::Error

The error parameter of TryFromError, returned from try_into_structural on conversion error. Read more

impl<T> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more