Struct ValidationConfig

pub struct ValidationConfig {
    pub enable_structural_validation: bool,
    pub enable_cross_table_validation: bool,
    pub enable_field_layout_validation: bool,
    pub enable_type_system_validation: bool,
    pub enable_semantic_validation: bool,
    pub enable_method_validation: bool,
    pub enable_token_validation: bool,
    pub max_nesting_depth: usize,
}
Expand description

Configuration for controlling validation behavior and performance. Configuration for metadata validation during assembly loading.

Controls the depth and scope of validation performed during .NET assembly loading. The loading process already performs essential structural validation (token format, table structure, heap references, signature format, basic type references). This configuration controls additional semantic validation that requires cross-table analysis.

§Design Philosophy

The validation system is designed with performance in mind:

  • Basic structural validation is always recommended
  • Expensive semantic validations can be selectively disabled
  • Configuration presets provide common validation scenarios
  • Fine-grained control allows optimization for specific use cases

§Validation Layers

  1. Structural: Token integrity, heap references (fast)
  2. Cross-table: Reference consistency between tables (moderate)
  3. Semantic: ECMA-335 compliance, logical consistency (variable)
  4. Type system: Inheritance, generics, constraints (expensive)

§Thread Safety

This struct is Copy and all fields are simple values, making it inherently thread-safe for concurrent use across multiple assembly loading operations.

Fields§

§enable_structural_validation: bool

Enable basic structural validation during table loading (recommended: always true) Note: Most structural validation is done during loading; this adds extra safety checks

§enable_cross_table_validation: bool

Enable expensive cross-table validation after loading (can be disabled for performance) Validates semantic consistency across metadata tables

§enable_field_layout_validation: bool

Enable field layout validation (overlap detection, offset validation) Only useful for types with explicit layout; detects problematic overlaps

§enable_type_system_validation: bool

Enable type system validation (inheritance chains, generic constraints) Validates logical consistency of type hierarchies and generic constraints

§enable_semantic_validation: bool

Enable semantic validation (method consistency, access modifiers, abstract/concrete rules) Validates logical consistency of type and method semantics

§enable_method_validation: bool

Enable method validation (constructor rules, virtual method consistency) Validates method-specific semantic rules

§enable_token_validation: bool

Enable token validation (cross-reference consistency, token relationship validation) Validates token references and relationships beyond basic loading

§max_nesting_depth: usize

Maximum nesting depth for nested classes (default: 64)

Implementations§

§

impl ValidationConfig

pub fn disabled() -> Self

Creates a disabled validation configuration for maximum performance.

⚠️ Warning: This disables ALL validation checks, including basic structural validation. Use only when you absolutely trust the assembly format and need maximum performance. Malformed assemblies may cause panics or undefined behavior.

§Use Cases
  • Parsing known-good assemblies in performance-critical loops
  • Bulk processing of trusted assembly collections
  • Scenarios where external validation has already been performed
§Risks
  • No protection against malformed metadata
  • Potential for crashes on invalid data
  • Silent acceptance of ECMA-335 violations

pub fn minimal() -> Self

Creates a minimal validation configuration for maximum performance.

Enables only essential structural validation while disabling expensive semantic checks. Provides a good balance between safety and performance for most use cases.

§What’s Validated
  • Basic token format and resolution
  • Table structure integrity
  • Heap reference validity
  • Signature format correctness
§What’s Skipped
  • Cross-table relationship validation
  • Type system consistency checks
  • Semantic rule enforcement
  • Method signature validation

pub fn comprehensive() -> Self

Creates a comprehensive validation configuration for maximum safety.

Enables all validation features to catch every possible metadata issue. Recommended for development, testing, and scenarios where correctness is more important than performance.

Note: May be slow for large assemblies with complex type hierarchies.

pub fn production() -> Self

Creates a validation configuration suitable for production use.

This configuration mirrors the validation performed by the .NET runtime, focusing on checks that would cause actual runtime failures. Based on analysis of CoreCLR and runtime source code.

§Validation Profile
  • Structural: ✅ Essential for basic safety
  • Cross-table: ✅ Runtime validates cross-references
  • Field layout: ❌ Runtime handles layout validation differently
  • Type system: ❌ Runtime validates lazily during type loading
  • Semantic: ✅ Runtime enforces ECMA-335 semantic rules
  • Method: ✅ Runtime enforces method constraints
  • Token: ❌ Runtime validates only critical token references

This provides excellent runtime compatibility while maintaining good performance.

pub fn strict() -> Self

Creates a validation configuration with all checks enabled.

Similar to comprehensive() but with explicit emphasis on strictness. All validation categories are enabled with maximum sensitivity.

⚠️ Warning: Field layout validation may produce false positives on legitimate overlapping fields (unions, explicit layout structs). Review results carefully when working with low-level interop types.

Trait Implementations§

§

impl Clone for ValidationConfig

§

fn clone(&self) -> ValidationConfig

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 ValidationConfig

§

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

Formats the value using the given formatter. Read more
§

impl Default for ValidationConfig

§

fn default() -> Self

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

impl PartialEq for ValidationConfig

§

fn eq(&self, other: &ValidationConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Copy for ValidationConfig

§

impl Eq for ValidationConfig

§

impl StructuralPartialEq for ValidationConfig

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.