Field

Struct Field 

Source
pub struct Field<Tag, Value> {
    pub value: Value,
    pub phantom: PhantomData<Tag>,
}
Expand description

The Field type, a.k.a. ω, is used to represent a named field entry within a product type or a sum type.

Field is parameterized by a phantom Tag type, which is used to represent the field name as type. Typically, this would either be a type-level string such as Symbol!("name"), or a type-level index such as Index<0>. Aside from that, Field is essentially a wrapper around Value.

Field is mainly used within the derived HasFields implementations, to include the field name in the generic product or sum representation of the given struct or enum.

Field is also shown as ω to improve the readability of compiler error messages. It is mainly useful when the type from HasFields::Fields is shown, which would contain a lot of Fields and tend to take up a lot of screen space to read.

§Example

Given the following struct definition:

#[derive(HasFields)]
pub struct MyContext {
    pub name: String,
    pub age: u8,
}

The following HasFields implementation would be generated:

impl HasFields for MyContext {
    type Fields = Product![Field<Symbol!("name"), String>, Field<Symbol!("age"), u8>];
}

which would be shown with the shortened representation as:

impl HasFields for MyContext {
    type Fields =
        π<ω<Symbol!("name"), String>,
            π<ω<Symbol!("age"), u8>,
                ε>>;
}

Fields§

§value: Value§phantom: PhantomData<Tag>

Trait Implementations§

Source§

impl<Tag, Value> Debug for ω<Tag, Value>
where Value: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<Tag, Value> From<Value> for ω<Tag, Value>

Source§

fn from(value: Value) -> ω<Tag, Value>

Converts to this type from the input type.
Source§

impl<Tag, Value> PartialEq for ω<Tag, Value>
where Value: PartialEq,

Source§

fn eq(&self, other: &ω<Tag, Value>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Tag, Value> Eq for ω<Tag, Value>
where Value: Eq,

Auto Trait Implementations§

§

impl<Tag, Value> Freeze for ω<Tag, Value>
where Value: Freeze,

§

impl<Tag, Value> RefUnwindSafe for ω<Tag, Value>
where Value: RefUnwindSafe, Tag: RefUnwindSafe,

§

impl<Tag, Value> Send for ω<Tag, Value>
where Value: Send, Tag: Send,

§

impl<Tag, Value> Sync for ω<Tag, Value>
where Value: Sync, Tag: Sync,

§

impl<Tag, Value> Unpin for ω<Tag, Value>
where Value: Unpin, Tag: Unpin,

§

impl<Tag, Value> UnwindSafe for ω<Tag, Value>
where Value: UnwindSafe, Tag: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Builder, Source, Output> CanBuildFrom<Source> for Builder
where Source: HasFields + IntoBuilder, <Source as HasFields>::Fields: FieldsBuilder<<Source as IntoBuilder>::Builder, Builder, Output = Output>,

Source§

type Output = Output

Source§

fn build_from(self, source: Source) -> Output

Source§

impl<Source, Target, Remainder> CanDowncastFields<Target> for Source
where Target: HasFields, <Target as HasFields>::Fields: FieldsExtractor<Source, Target, Remainder = Remainder>,

Source§

type Remainder = Remainder

Source§

fn downcast_fields( self, _tag: PhantomData<Target>, ) -> Result<Target, <Source as CanDowncastFields<Target>>::Remainder>

Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.