Struct tetsy_scale_info::Field[][src]

pub struct Field<T: Form = MetaForm> { /* fields omitted */ }

A field of a struct-like data type.

Name is optional so it can represent both named and unnamed fields.

This can be a named field of a struct type or an enum struct variant, or an unnamed field of a tuple struct.

Type name

The type_name field contains a string which is the name of the type of the field as it appears in the source code. The exact contents and format of the type name are not specified, but in practice will be the name of any valid type for a field e.g.

  • Concrete types e.g "u32", "bool", "Foo" etc.
  • Type parameters e.g "T", "U"
  • Generic types e.g "Vec<u32>", "Vec<T>"
  • Associated types e.g. "T::MyType", "<T as MyTrait>::MyType"
  • Type aliases e.g. "MyTypeAlias", "MyTypeAlias<T>"
  • Other built in Rust types e.g. arrays, references etc.

Note that the type name doesn't correspond to the underlying type of the field, unless using a concrete type directly. Any given type may be referred to by multiple field type names, when using generic type parameters and type aliases.

This is intended for informational and diagnostic purposes only. Although it is possible to infer certain properties e.g. whether a type name is a type alias, there are no guarantees provided, and the type name representation may change.

Implementations

impl Field[src]

pub fn new(
    name: Option<&'static str>,
    ty: MetaType,
    type_name: &'static str
) -> Self
[src]

Creates a new field.

Use this constructor if you want to instantiate from a given meta type.

pub fn named_of<T: ?Sized>(name: &'static str, type_name: &'static str) -> Field where
    T: TypeInfo + 'static, 
[src]

Creates a new named field.

Use this constructor if you want to instantiate from a given compile-time type.

pub fn unnamed_of<T: ?Sized>(type_name: &'static str) -> Field where
    T: TypeInfo + 'static, 
[src]

Creates a new unnamed field.

Use this constructor if you want to instantiate an unnamed field from a given compile-time type.

impl<T> Field<T> where
    T: Form
[src]

pub fn name(&self) -> Option<&T::String>[src]

Returns the name of the field. None for unnamed fields.

pub fn ty(&self) -> &T::Type[src]

Returns the type of the field.

pub fn type_name(&self) -> &T::String[src]

Returns a string which is the name of the type of the field as it appears in the source code. The exact contents and format of the type name are not specified, but in practice will be the name of any valid type for a field. This is intended for informational and diagnostic purposes only.

Trait Implementations

impl<T: Clone + Form> Clone for Field<T> where
    T::String: Clone,
    T::Type: Clone,
    T::String: Clone
[src]

impl<T: Debug + Form> Debug for Field<T> where
    T::String: Debug,
    T::Type: Debug,
    T::String: Debug
[src]

impl<T: Form> Decode for Field<T> where
    Option<T::String>: Decode,
    Option<T::String>: Decode,
    T::Type: Decode,
    T::Type: Decode,
    T::String: Decode,
    T::String: Decode
[src]

impl<T: Form> Encode for Field<T> where
    Option<T::String>: Encode,
    Option<T::String>: Encode,
    T::Type: Encode,
    T::Type: Encode,
    T::String: Encode,
    T::String: Encode
[src]

impl<T: Form> EncodeLike<Field<T>> for Field<T> where
    Option<T::String>: Encode,
    Option<T::String>: Encode,
    T::Type: Encode,
    T::Type: Encode,
    T::String: Encode,
    T::String: Encode
[src]

impl<T: Eq + Form> Eq for Field<T> where
    T::String: Eq,
    T::Type: Eq,
    T::String: Eq
[src]

impl IntoPortable for Field[src]

type Output = Field<PortableForm>

The portable version of Self.

impl<T: Ord + Form> Ord for Field<T> where
    T::String: Ord,
    T::Type: Ord,
    T::String: Ord
[src]

impl<T: PartialEq + Form> PartialEq<Field<T>> for Field<T> where
    T::String: PartialEq,
    T::Type: PartialEq,
    T::String: PartialEq
[src]

impl<T: PartialOrd + Form> PartialOrd<Field<T>> for Field<T> where
    T::String: PartialOrd,
    T::Type: PartialOrd,
    T::String: PartialOrd
[src]

impl<T: Form> StructuralEq for Field<T>[src]

impl<T: Form> StructuralPartialEq for Field<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Field<T> where
    <T as Form>::String: RefUnwindSafe,
    <T as Form>::Type: RefUnwindSafe
[src]

impl<T> Send for Field<T> where
    <T as Form>::String: Send,
    <T as Form>::Type: Send
[src]

impl<T> Sync for Field<T> where
    <T as Form>::String: Sync,
    <T as Form>::Type: Sync
[src]

impl<T> Unpin for Field<T> where
    <T as Form>::String: Unpin,
    <T as Form>::Type: Unpin
[src]

impl<T> UnwindSafe for Field<T> where
    <T as Form>::String: UnwindSafe,
    <T as Form>::Type: UnwindSafe
[src]

Blanket Implementations

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

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

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

impl<S> Codec for S where
    S: Encode + Decode
[src]

impl<T> DecodeAll for T where
    T: Decode
[src]

impl<T> DecodeLimit for T where
    T: Decode
[src]

impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ mut T> for T where
    T: Encode
[src]

impl<T> EncodeLike<Arc<T>> for T where
    T: Encode
[src]

impl<T> EncodeLike<Box<T, Global>> for T where
    T: Encode
[src]

impl<'a, T> EncodeLike<Cow<'a, T>> for T where
    T: Encode + ToOwned
[src]

impl<T> EncodeLike<Rc<T>> for T where
    T: Encode
[src]

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

impl<S> FullCodec for S where
    S: Decode + FullEncode
[src]

impl<S> FullEncode for S where
    S: Encode + EncodeLike<S>, 
[src]

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

impl<T> KeyedVec for T where
    T: Codec
[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.