Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime(/* private fields */);
Expand description

A handle to a running .NET runtime. Cheap to clone.

Implementations§

Source§

impl Runtime

Source

pub fn coreclr() -> Result<Self>

Starts CoreCLR with the newest installed framework, or returns the already running instance. Only one CoreCLR can run per process.

Source

pub fn coreclr_with(options: &CoreClrOptions) -> Result<Self>

Starts CoreCLR with options. The options are ignored if it is already running.

Source

pub fn coreclr_attach( host_handle: *mut c_void, domain_id: u32, create_delegate: *const c_void, major: u16, ) -> Result<Self>

Attaches to a CoreCLR already running in this process, for a native mod loaded into a .NET game (e.g. Godot on CoreCLR). host_handle, domain_id and create_delegate (coreclr_create_delegate) are captured as the game’s runtime initialises — see the hao-godot crate; major is the .NET major version. After this, assemblies can be loaded and methods called as usual. Returns the existing handle if hao already has one.

Source

pub fn mono(options: &MonoOptions) -> Result<Self>

Starts Mono, or returns the already running instance.

Source

pub fn mono_attach(options: &MonoOptions) -> Result<Self>

Attaches to a Mono runtime already running in this process, for a mod loaded into a Unity Mono game. options.library should point at the game’s own Mono. After this, assemblies can be loaded and methods called as usual. Returns the existing handle if hao already has one.

Source

pub fn backend(&self) -> Backend

Source

pub fn attach_thread(&self)

Lets the calling thread run managed code. Needed for Mono on threads it didn’t start, a no-op on CoreCLR. Binding calls do this automatically.

Source

pub fn load_assembly(&self, path: impl AsRef<Path>) -> Result<()>

Loads an assembly and makes it available to later loads by name.

Source

pub fn load_assembly_bytes(&self, name: &str, bytes: &[u8]) -> Result<()>

Loads an assembly from memory. name is its assembly name.

Source

pub fn load_module(&self, module: &Module) -> Result<()>

Loads a module built or edited with hao, without writing it to disk.

Source

pub fn function_pointer( &self, assembly: &str, type_name: &str, method: &str, ) -> Result<*const c_void>

A native pointer to the static method type_name::method in assembly.

On CoreCLR the method must be [UnmanagedCallersOnly]; for a method that isn’t, use method_pointer instead, which calls any method by JIT-compiling it. On Mono the returned thunk takes an extra trailing *mut *mut c_void exception argument.

Source

pub fn method_pointer( &self, assembly: &str, type_name: &str, method: &str, ) -> Result<*const c_void>

A native-callable pointer to a static method, whether or not it is [UnmanagedCallersOnly]. The method is JIT-compiled first, so IL patched before the assembly was loaded takes effect.

The pointer uses the managed calling convention, which matches a plain extern "C" fn(args) -> ret for static methods with primitive and pointer arguments. Unlike function_pointer, it takes no trailing exception argument on either backend, so a managed exception crosses it as an unhandled error.

Trait Implementations§

Source§

impl Clone for Runtime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Runtime

Source§

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

Formats the value using the given formatter. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more