RustClr

Struct RustClr 

Source
pub struct RustClr<'a> { /* private fields */ }
Expand description

Represents a Rust interface to the Common Language Runtime (CLR).

§Example

use rustclr::{RustClr, RuntimeVersion};
use std::fs;
 
// Load a sample .NET assembly into a buffer
let buffer = fs::read("examples/sample.exe")?;
let mut clr = RustClr::new(&buffer)?
    .with_runtime_version(RuntimeVersion::V4)
    .with_domain("CustomDomain")
    .with_args(vec!["arg1", "arg2"])
    .with_output();
 
let output = clr.run()?;
println!("Output: {}", output);

Implementations§

Source§

impl<'a> RustClr<'a>

Source

pub fn new<T: Into<ClrSource<'a>>>(source: T) -> Result<Self>

Creates a new RustClr.

§Errors

Returned when the file cannot be read or when the buffer does not represent a valid .NET executable.

Source

pub fn with_runtime_version(self, version: RuntimeVersion) -> Self

Sets the .NET runtime version to use.

Source

pub fn with_domain(self, domain_name: &str) -> Self

Sets the application domain name.

Source

pub fn with_args(self, args: Vec<&str>) -> Self

Sets arguments to be passed to the assembly’s entry point.

Source

pub fn with_output(self) -> Self

Enables or disables output redirection.

Source

pub fn with_patch_exit(self) -> Self

Enables patching of the System.Environment.Exit method in mscorlib.

Source

pub fn run(&mut self) -> Result<String>

Loads the .NET assembly and runs its entry point.

§Errors

Returned when CLR initialization fails, when the assembly cannot be loaded, when Main cannot be invoked, or when output capture is enabled but fails.

Trait Implementations§

Source§

impl<'a> Clone for RustClr<'a>

Source§

fn clone(&self) -> RustClr<'a>

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
Source§

impl<'a> Debug for RustClr<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for RustClr<'a>

Source§

fn default() -> RustClr<'a>

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

impl Drop for RustClr<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RustClr<'a>

§

impl<'a> RefUnwindSafe for RustClr<'a>

§

impl<'a> !Send for RustClr<'a>

§

impl<'a> !Sync for RustClr<'a>

§

impl<'a> Unpin for RustClr<'a>

§

impl<'a> UnwindSafe for RustClr<'a>

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> 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.