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
impl Object
sourcepub fn unbox<T: InteropBox + Copy>(&self) -> T
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>();
}
sourcepub fn box_val<T: InteropBox>(domain: &Domain, data: T) -> Self
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?`
sourcepub fn get_virtual_method<T: TupleToPtrs + CompareClasses + InteropSend>(
obj: &Self,
method: &Method<T>
) -> Option<Method<T>>where
<T as InteropSend>::TargetType: TupleToPtrs,
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
impl Object
sourcepub fn clone_managed_object(&self) -> Self
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 InteropClass for Object
impl InteropClass for Object
fn get_mono_class() -> Class
source§impl ObjectTrait for Object
impl ObjectTrait for Object
source§unsafe fn from_ptr_unchecked(obj_ptr: *mut MonoObject) -> Self
unsafe fn from_ptr_unchecked(obj_ptr: *mut MonoObject) -> Self
fn cast<Target: ObjectTrait>(&self) -> Option<Target>
source§fn hash(&self) -> i32
fn hash(&self) -> i32
source§fn get_size(&self) -> u32
fn get_size(&self) -> u32
source§impl<O: ObjectTrait> PartialEq<O> for Object
impl<O: ObjectTrait> PartialEq<O> for Object
Auto Trait Implementations§
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnwindSafe for Object
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> InteropRecive for Twhere
T: ObjectTrait,
impl<T> InteropRecive for Twhere T: ObjectTrait,
§type SourceType = *mut _MonoObject
type SourceType = *mut _MonoObject
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
fn get_rust_rep(src: <T as InteropRecive>::SourceType) -> T
Self::SourceType
to type implementing InteropRecive
trait.source§impl<T> InteropSend for Twhere
T: ObjectTrait,
impl<T> InteropSend for Twhere T: ObjectTrait,
§type TargetType = *mut _MonoObject
type TargetType = *mut _MonoObject
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
fn get_mono_rep(src: T) -> <T as InteropSend>::TargetType
InteropRecive
trait to type that should be returned to MonoRuntime
.