logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![allow(clippy::unused_self)] // it's an example!

use crate::ffi::example_automatic as ffi;
use crate::Error;

/// APIs often have some module side state associated with them and use a struct
/// or enum as a high level API object the state can be stored in. For our
/// Example API we just have an empty struct.
pub struct Example {}

impl Example {
    /// The wrapper is usually extremely thin, and can be inlined
    #[inline]
    pub fn is_ready(&self, name: &str, max: u32) -> Result<ffi::IsReady, Error> {
        ffi::is_ready(name, max, ffi::State::SomeStateX).map_err(Error::from)
    }

    #[inline]
    pub fn ret_byte_vector() -> Result<Vec<u8>, Error> {
        ffi::ret_byte_vector().map_err(Error::from)
    }

    #[inline]
    pub fn ret_string() -> Result<String, Error> {
        ffi::ret_string().map_err(Error::from)
    }

    #[inline]
    pub fn works(&self) -> Result<(), Error> {
        ffi::works().map_err(Error::from)
    }

    #[inline]
    pub fn infallible_number(x: u32) -> u32 {
        ffi::infallible_number(x)
    }
}