Struct wrapped_mono::Object

source ·
pub struct Object { /* private fields */ }
Expand description

Safe representation of a refernece to a manged Object. Is not nullable when passed between managed and unmanged code(e.g when added as an argument to function exposed as an interna call). It means that while it may represent a nullable type, wrapped-mono will automaticly panic when recived null value. For nullable support use Option<Object>.

Implementations§

source§

impl Object

source

pub fn new(domain: &Domain, class: &Class) -> Self

Allocates new object of Class class. Does not call the constructor, to call constuctor call the .ctor method after creating the object.

Examples
let new_obj = Object::new(&domain,&class);
source

pub unsafe fn from_ptr(obj_ptr: *mut MonoObject) -> Option<Self>

Creates new Object from pointer obj_ptr. Checks if it is null, and returns None if so.

Safety

obj_ptr must be either a valid [MonoObject] pointer or null, otherwise resulting Object will not be valid and will cause crashes.

source

pub fn unbox<T: InteropBox + Copy>(&self) -> T

Unboxes the value in Object self.

Safety

Calling it on a type which can’t be unboxed will lead to a crash.

Panics

Type T must match the unboxed managed type. Unboxing type C#

int num = 123;
Object boxed = num;
RustFunction(boxed);

Rust

#[invokable]
fn rust_function(o:Object){
    let val = o.unbox::<i32>();
}
source

pub fn box_val<T: InteropBox>(domain: &Domain, data: T) -> Self

Boxes value into an object.

Examples
 let mut val:i32 = 0;
 let obj = Object::box_val::<i32>(&domain,val); //New object of type `Int32?`
source

pub fn get_virtual_method<T: TupleToPtrs + CompareClasses + InteropSend>( obj: &Self, method: &Method<T> ) -> Option<Method<T>>where <T as InteropSend>::TargetType: TupleToPtrs,

Gets an implementation virtual Method method for a specific Object obj.

Explanation

with given C# code

 class ParrentClass{
     virtual void SomeMehod(){
         //SomeFunction
     }
 }
 class ChildClass : ParrentClass{
     override void SomeMehod(){
         ///SomeOtherFunction
     }
 }

When you callget_vitual_method on object that is instance of ChildClass and method ParrentClass::SomeMethod you will get return value of ChildClass::SomeMethod.

source§

impl Object

source

pub fn clone_managed_object(&self) -> Self

Clones the underlying [MonoObject] not the reference to this object. (e.g when called on a reference to a managed object A will create second object B, not another reference to object A).

Trait Implementations§

source§

impl Clone for Object

source§

fn clone(&self) -> Self

Returns a copy 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 InteropClass for Object

source§

impl ObjectTrait for Object

source§

fn get_ptr(&self) -> *mut MonoObject

Gets internal [MonoObject] pointer.

source§

unsafe fn from_ptr_unchecked(obj_ptr: *mut MonoObject) -> Self

Creates new instance of Self from *mut [MonoObject]. Pointer is guaranteed to be not null, and of type which can be assigned to managed type represented by Self. Read more
source§

fn cast<Target: ObjectTrait>(&self) -> Option<Target>

source§

unsafe fn from_ptr(obj_ptr: *mut MonoObject) -> Option<Self>

Creates new instance of Self from *mut [MonoObject]. Returns None if either obj_ptr is null OR object obj_ptr points to is of a type which does not derive from the managed type Self represents. Read more
source§

fn hash(&self) -> i32

get hash of this object: This hash is not based on values of objects fields, and differs from result of calling object.GetHash() Read more
source§

fn get_domain(&self) -> Domain

get Domain this object exists in. Read more
source§

fn get_size(&self) -> u32

get size of managed object referenced by self in bytes. Does include builtin hidden data. Read more
source§

fn get_class(&self) -> Class

Returns Class of this object. NOTE: This is function returns the class of the underlying object, not class represented by Self. This means that class returned from get_class may be a class derived from class Self represents. Read more
source§

fn to_mstring(&self) -> Result<Option<MString>, Exception>

Returns result of calling ToString on this Object. Read more
source§

impl<O: ObjectTrait> PartialEq<O> for Object

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> InteropRecive for Twhere T: ObjectTrait,

§

type SourceType = *mut _MonoObject

Souce type used by MonoRuntime when calling functions exposed by add_internal_call, or getting a value back from a method, that can be converted to a rust type.
source§

fn get_rust_rep(src: <T as InteropRecive>::SourceType) -> T

Function converting Self::SourceType to type implementing InteropRecive trait.
source§

impl<T> InteropSend for Twhere T: ObjectTrait,

§

type TargetType = *mut _MonoObject

Type used by MonoRuntime, that type implementing InteropSend trait should be converted to when returning it to MonoRuntime.
source§

fn get_mono_rep(src: T) -> <T as InteropSend>::TargetType

Function converting type implementing InteropRecive trait to type that should be returned to MonoRuntime.
source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.