Struct Field

pub struct Field {
    pub rid: u32,
    pub token: Token,
    pub offset: usize,
    pub flags: u32,
    pub name: String,
    pub signature: SignatureField,
    pub default: OnceLock<CilPrimitive>,
    pub rva: OnceLock<u32>,
    pub layout: OnceLock<u32>,
    pub marshal: OnceLock<MarshallingInfo>,
    pub custom_attributes: CustomAttributeValueList,
}
Expand description

Represents a field definition with resolved indexes and owned data.

A field defines a data member of a type, including instance fields, static fields, and compile-time constants (literals). This structure contains all resolved information about the field, including its signature, optional default value, marshalling information, and custom attributes.

§Field Types

  • Instance fields: Non-static data members of a class or value type
  • Static fields: Class-level data members shared across all instances
  • Literals: Compile-time constants with default values

§ECMA-335 Reference

See ECMA-335, Partition II, §22.15 for the complete Field table specification.

Fields§

§rid: u32

The row identifier in the Field table.

This 1-based index uniquely identifies this field within the Field table. Combined with the table type, it forms the field’s unique identity.

§token: Token

The metadata token for this field.

A crate::metadata::token::Token that uniquely identifies this field across the entire assembly. The token encodes both the table type (Field) and the row ID.

§offset: usize

The byte offset of this field in the metadata tables stream.

This offset points to the start of this field’s row data within the metadata tables stream, used for binary parsing and navigation.

§flags: u32

Field attributes and flags.

A 2-byte bitmask of type FieldAttributes as defined in ECMA-335, §II.23.1.5. This includes accessibility modifiers, static/instance designation, and special flags like HasDefault, HasFieldRVA, and HasFieldMarshal.

Common flag values:

  • 0x0001: CompilerControlled
  • 0x0002: Private
  • 0x0003: FamANDAssem
  • 0x0004: Assembly
  • 0x0005: Family
  • 0x0006: FamORAssem
  • 0x0007: Public
  • 0x0010: Static
  • 0x0020: Literal
  • 0x0040: NotSerialized
  • 0x0080: HasFieldRVA
  • 0x1000: HasDefault
  • 0x2000: HasFieldMarshal
§name: String

The name of the field.

A string from the String heap containing the field’s identifier name. This name is used for field resolution and debugging information.

§signature: SignatureField

The field’s type signature.

A crate::metadata::signatures::SignatureField that describes the field’s type, including primitive types, object references, value types, and arrays. This signature is parsed from the Blob heap.

§default: OnceLock<CilPrimitive>

Default value for this field (lazy-loaded).

Contains the default value if the field has the HasDefault flag set. This is typically used for literal fields and fields with explicit default values. The value is loaded on-demand from the Constant table.

§rva: OnceLock<u32>

Relative Virtual Address for field data (lazy-loaded).

Contains the RVA if the field has the HasFieldRVA flag set. This points to the field’s initial data in the PE file, typically used for static fields with explicit initial values.

§layout: OnceLock<u32>

Field layout offset within the containing type (lazy-loaded).

A 4-byte value specifying the byte offset of the field within its containing class or value type. This is loaded from the FieldLayout table when explicit field positioning is used.

§marshal: OnceLock<MarshallingInfo>

Field marshalling information (lazy-loaded).

Contains marshalling information if the field has the HasFieldMarshal flag set. This describes how the field should be marshalled when crossing managed/unmanaged boundaries.

§custom_attributes: CustomAttributeValueList

Custom attributes applied to this field.

A collection of custom attributes that provide additional metadata for this field, such as serialization hints, validation attributes, or framework-specific annotations.

Auto Trait Implementations§

§

impl !Freeze for Field

§

impl RefUnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnwindSafe for Field

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.