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>