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
impl FileBuilder
pub fn new() -> Self
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 contains_metadata(self) -> Self
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
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
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>
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
impl Clone for FileBuilder
§fn clone(&self) -> FileBuilder
fn clone(&self) -> FileBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for FileBuilder
impl Debug for FileBuilder
§impl Default for FileBuilder
impl Default for FileBuilder
§fn default() -> FileBuilder
fn default() -> FileBuilder
Auto Trait Implementations§
impl Freeze for FileBuilder
impl RefUnwindSafe for FileBuilder
impl Send for FileBuilder
impl Sync for FileBuilder
impl Unpin for FileBuilder
impl UnwindSafe for FileBuilder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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