Macro interoptopus::pattern

source ·
macro_rules! pattern {
    ($x:path) => { ... };
}
Expand description

Register a pattern with an InventoryBuilder.

You only need to register LibraryPattern, as TypePattern are detected automatically.

§Example

Note, as this example focuses on the pattern macro it omits the definition of Error and MyFFIError. Their implementation can be found in the FFIError example.

use interoptopus::{ffi_type, ffi_service, ffi_service_ctor, Inventory, InventoryBuilder, pattern};


#[ffi_type(opaque)]
pub struct SimpleService {
    pub some_value: u32,
}

#[ffi_service(error = "MyFFIError", prefix = "simple_service_")]
impl SimpleService {

    #[ffi_service_ctor]
    pub fn new_with(some_value: u32) -> Result<Self, Error> {
        Ok(Self { some_value })
    }
}

pub fn inventory() -> Inventory {
    InventoryBuilder::new()
        .register(pattern!(SimpleService))
        .inventory()
}