voa

Crates.iovoa
lib.rsvoa
version0.0.0
sourcesrc
created_at2023-12-04 10:05:37.587884
updated_at2023-12-04 10:05:37.587884
descriptionCheck whether a type implements a trait
homepage
repositoryhttps://github.com/oovm/sub_projects
max_upload_size
id1057495
size3,891
SasakiSaki (oovm)

documentation

https://docs.rs/voa

README

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
}
Commit count: 0

cargo fmt