Trait wrapped_mono::ObjectTrait
source · pub trait ObjectTrait: Sized + InteropClass {
// Required methods
fn get_ptr(&self) -> *mut MonoObject;
unsafe fn from_ptr_unchecked(obj: *mut MonoObject) -> Self;
// Provided methods
fn cast<Target: ObjectTrait>(&self) -> Option<Target> { ... }
unsafe fn from_ptr(obj_ptr: *mut MonoObject) -> Option<Self> { ... }
fn hash(&self) -> i32 { ... }
fn get_domain(&self) -> Domain { ... }
fn get_size(&self) -> u32 { ... }
fn get_class(&self) -> Class { ... }
fn to_mstring(&self) -> Result<Option<MString>, Exception> { ... }
}
Expand description
Trait contining functions common for all types of manged objects.
Required Methods§
sourceunsafe fn from_ptr_unchecked(obj: *mut MonoObject) -> Self
unsafe fn from_ptr_unchecked(obj: *mut MonoObject) -> Self
Provided Methods§
fn cast<Target: ObjectTrait>(&self) -> Option<Target>
sourcefn hash(&self) -> i32
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()
Example
let object = Object::new(&domain,&class);
let object_copy = object.clone_managed_object();
assert!(object.hash() != object_copy.hash()); // Objects object and object_copy have exacly
// the same values of their fileds, but are diffrent instances, so their hash is diffrent.
sourcefn get_domain(&self) -> Domain
fn get_domain(&self) -> Domain
sourcefn get_size(&self) -> u32
fn get_size(&self) -> u32
get size of managed object referenced by self in bytes. Does include builtin hidden data.
Example
ⓘ
class SomeClass{};
class OtherClass{int some_int;};
let size = some_obj.get_size(); //Get size of some_obj(in this case an instance of SomeClass)
assert!(size == std::mem::size_of::<MonoObject>() as u32); // 8 bytes on 32 bit systems, 16 on 64 bit ones (size of two pointers).
let size_other = other_obj.get_size(); //Get size of other_obj(in this case an instance of OtherClass)
assert!(size_other == (std::mem::size_of::<MonoObject>() + std::mem::size_of::<i32>()) as u32); //size of two hidden pointers + some_int filed.
sourcefn get_class(&self) -> Class
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.
Example
let object = Object::new(&domain,&class);
let object_class = object.get_class();
assert!(class == object_class);
sourcefn to_mstring(&self) -> Result<Option<MString>, Exception>
fn to_mstring(&self) -> Result<Option<MString>, Exception>
Returns result of calling ToString
on this Object
.
Errors
Returns Exception
if raised, and Option<MString>
if not. Function returns Option<MString>
to allow for null value to be returned.