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: u32The 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: TokenThe 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: usizeThe 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: u32Field 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: CompilerControlled0x0002: Private0x0003: FamANDAssem0x0004: Assembly0x0005: Family0x0006: FamORAssem0x0007: Public0x0010: Static0x0020: Literal0x0040: NotSerialized0x0080: HasFieldRVA0x1000: HasDefault0x2000: HasFieldMarshal
name: StringThe 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: SignatureFieldThe 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: CustomAttributeValueListCustom 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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