docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

core::reflect::field

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

Field, one field of a struct or variant.

Structs

FieldSource

pub struct Field

One field of an Inspect struct, or of one variant of an enum.

  • pub fn name(self) -> str§

    Source

    The name; "0", "1", .. in a tuple struct or variant.

  • pub fn renamed_from(self) -> str§

    Source

    The name it had before a #[renamed_from("..")], else empty.

  • pub fn type_ref(self) -> TypeRef§

    Source

    Its type.

  • pub fn offset(self) -> usize§

    Source

    Its offset in bytes from the start of the value; usize::MAX when it has no fixed place.

  • pub fn index(self) -> usize§

    Source

    Its position in declaration order.

  • pub fn is_pub(self) -> bool§

    Source

    A plain pub field.

  • pub fn has_default(self) -> bool§

    Source

    It has a = expr default.

  • pub fn attr<A>(self) -> A | none§

    Source

    The runtime attribute A on the field, if it has one: f.attr::<Range>().

  • pub fn attrs(self) -> List<Attr>§

    Source

    The runtime attributes on the field.

  • pub fn get(self, owner: any) -> any | none§

    Source

    The field's value in owner; none when owner is not of the field's type (or holds another variant).

  • pub fn get_as<T>(self, owner: any) -> T | none§

    Source

    The field's value as a T, as cast::<T>(field.get(owner)).

  • pub fn set(self, ref owner: any, value: any) -> bool§

    Source

    Sets the field in owner to value; false when owner is not of the field's type or value does not fit it (an integer fits when its value does). owner gets a changed copy: a struct is a value. A variant's payload is read-only.

Trait implementations 2