Crates.io | voa |
lib.rs | voa |
version | 0.0.0 |
source | src |
created_at | 2023-12-04 10:05:37.587884 |
updated_at | 2023-12-04 10:05:37.587884 |
description | Check whether a type implements a trait |
homepage | |
repository | https://github.com/oovm/sub_projects |
max_upload_size | |
id | 1057495 |
size | 3,891 |
Check whether a type implements a trait
use instance::{define_interface, Interface};
define_interface!(TypeSize);
trait TypeSize {
fn type_size(&self) -> usize;
}
struct WasmI32(i32);
struct WasmI64(i64);
impl TypeSize for WasmI32 {
fn type_size(&self) -> usize {
4
}
}
fn main() {
let v1 = WasmI32(0);
let object = v1.cast();
println!("{:?}", object.map(|v| v.meta_data())); // 4
let v2 = WasmI64(0);
let object = Interface::<dyn TypeSize>::recast(&v2);
println!("{:?}", object.map(|v| v.meta_data())); // None
}