Struct FileBuilder

pub struct FileBuilder { /* private fields */ }
Expand description

Builder for creating File table entries.

FileBuilder provides a fluent API for creating entries in the File metadata table, which contains information about files that are part of multi-file assemblies.

§Purpose

The File table serves several key functions:

  • Multi-file Assembly Support: Lists additional files in assemblies
  • Module References: References to .netmodule files with executable code
  • Resource Files: References to .resources files with binary data
  • Native Libraries: References to unmanaged DLLs for P/Invoke
  • Integrity Verification: Hash values for file validation

§Builder Pattern

The builder provides a fluent interface for constructing File entries:

let hash_bytes = vec![0x01, 0x02, 0x03, 0x04]; // Example hash

let file_token = FileBuilder::new()
    .name("MyLibrary.netmodule")
    .contains_metadata()
    .hash_value(&hash_bytes)
    .build(&mut context)?;

§Validation

The builder enforces the following constraints:

  • Name Required: A file name must be provided
  • Name Not Empty: File names cannot be empty strings
  • Hash Format: Hash values can be empty but must be valid blob data

§Integration

File entries integrate with other metadata structures:

  • ManifestResource: Resources can reference files
  • ExportedType: Types can be forwarded to files
  • Assembly Loading: Runtime uses file information for loading

Implementations§

§

impl FileBuilder

pub fn new() -> Self

Creates a new FileBuilder instance.

Returns a builder with all fields unset, ready for configuration through the fluent API methods. File attributes default to CONTAINS_META_DATA (0x0000).

§Examples
let builder = FileBuilder::new();

pub fn name(self, name: impl Into<String>) -> Self

Sets the name of the file.

The file name typically includes the file extension (e.g., “MyModule.netmodule”, “Resources.resources”).

§Arguments
  • name - The name of the file
§Examples
let builder = FileBuilder::new()
    .name("MyLibrary.netmodule");

pub fn flags(self, flags: u32) -> Self

Sets file attributes using a bitmask.

File attributes specify the type and characteristics of the file. Use the FileAttributes constants for standard values.

§Arguments
  • flags - File attributes bitmask
§Examples
let builder = FileBuilder::new()
    .flags(FileAttributes::CONTAINS_NO_META_DATA);

pub fn contains_metadata(self) -> Self

Marks the file as containing .NET metadata.

This is appropriate for .netmodule files and other executable modules that contain .NET metadata and can define types and methods.

§Examples
let builder = FileBuilder::new()
    .name("MyModule.netmodule")
    .contains_metadata();

pub fn contains_no_metadata(self) -> Self

Marks the file as containing no .NET metadata.

This is appropriate for resource files, images, configuration data, or unmanaged libraries that do not contain .NET metadata.

§Examples
let builder = FileBuilder::new()
    .name("Resources.resources")
    .contains_no_metadata();

pub fn hash_value(self, hash: &[u8]) -> Self

Sets the hash value for file integrity verification.

The hash value is used to verify that the file hasn’t been tampered with or corrupted. This is typically a SHA-1 or SHA-256 hash.

§Arguments
  • hash - The hash data for verification
§Examples
let hash = vec![0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0];
let builder = FileBuilder::new()
    .hash_value(&hash);

pub fn build(self, context: &mut BuilderContext) -> Result<Token>

Builds the File entry and adds it to the assembly.

This method validates all required fields, adds any strings and blobs to the appropriate heaps, creates the File table entry, and returns the metadata token for the new entry.

§Arguments
  • context - The builder context for the assembly being modified
§Returns

Returns the metadata token for the newly created File entry.

§Errors

Returns an error if:

  • The file name is not set
  • The file name is empty
  • There are issues adding strings or blobs to heaps
  • There are issues adding the table row
§Examples

let file_token = FileBuilder::new()
    .name("MyModule.netmodule")
    .contains_metadata()
    .build(&mut context)?;

println!("Created File with token: {}", file_token);

Trait Implementations§

§

impl Clone for FileBuilder

§

fn clone(&self) -> FileBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for FileBuilder

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for FileBuilder

§

fn default() -> FileBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.