Crates.io | nanocom |
lib.rs | nanocom |
version | 0.2.1 |
source | src |
created_at | 2022-09-05 00:30:12.458585 |
updated_at | 2022-10-31 08:09:36.652149 |
description | Nano-COM, extremly small subset of cross-platform COM |
homepage | https://github.com/functionalscript/functionalscript/tree/main/com/rust/nanocom |
repository | https://github.com/functionalscript/functionalscript |
max_upload_size | |
id | 658500 |
size | 19,006 |
See Nano-COM.
let o: Object<IMy> = ...;
// calling a public function
let i: u32 = o.B();
trait IMyEx {
// a definition
fn B(&self) -> u32;
}
impl IMyEx for Object<IMy> {
// an implementation of the public function
fn B(&self) -> u32 {
// calling a virtual function.
unsafe { (self.interface().B()(self) }
}
}
#[repr(C)]
pub struct IMy {
// a definiton of the virtual function
pub B: unsafe extern "stdcall" fn(this: &Object<IMy>) -> u32
}
trait IMyVmtFn: Class<Interface = IMy>
where
CObject<Self>: IMyEx
{
// an implementation of the virtual function
extern "stdcall" fn B(this: &Object<IMy>) -> u32 {
// calling a function implementation
unsafe { Self::to_cobject(this) }.B()
}
}
trait IMyEx {
// a definition
fn B(&self) -> u32;
}
impl IMyEx for CObject<X> {
// an implementation of the function.
fn B(&self) -> u32 {
self.value.0
}
}