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
use crate::Error;
/// Representation of scalar types supported by Menoh.
pub unsafe trait Dtype {
/// Integer specifying the scalar type.
///
/// ```
/// # use menoh::*;
/// assert_eq!(f32::ID, menoh_sys::menoh_dtype_float as menoh_sys::menoh_dtype);
/// ```
const ID: menoh_sys::menoh_dtype;
/// Verify a scalar type.
///
/// ```
/// # use menoh::*;
/// assert!(f32::check(f32::ID).is_ok());
/// assert!(f32::check(f32::ID + 1).is_err());
/// ```
fn check(dtype: menoh_sys::menoh_dtype) -> Result<(), Error> {
if dtype == Self::ID {
Ok(())
} else {
Err(Error::DtypeMismatch {
actual: dtype,
expected: Self::ID,
})
}
}
}
unsafe impl Dtype for f32 {
const ID: menoh_sys::menoh_dtype = menoh_sys::menoh_dtype_float as _;
}
#[cfg(test)]
mod tests;