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§

source

fn get_ptr(&self) -> *mut MonoObject

Gets the internal [MonoObject] pointer.

source

unsafe fn from_ptr_unchecked(obj: *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.

Safety

The pointer must not be null, and point to a managed Object of either type represented by Self or a type derived from it.

Provided Methods§

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.

Safety

Pointer must either be null, or point to a managed object.

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()

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

fn get_domain(&self) -> Domain

get Domain this object exists in.

Example
 let domain = Domain::create(); //create Domain dom
 let object = Object::new(&domain,&class); //create object in Domain dom.
 let obj_domain = object.get_domain(); //get doamin object is in
 assert!(domain == obj_domain);
source

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

Example
let object = Object::new(&domain,&class);
let object_class = object.get_class();
assert!(class == object_class);
source

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.

Implementors§