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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![feature(generators, generator_trait)]
#![warn(clippy::all)]
mod device;
mod discovered_device;
mod driver;
mod errors;
pub use crate::{device::*, discovered_device::*, driver::*, errors::*};
pub type Result<T> = std::result::Result<T, FPrintError>;
#[derive(Debug, Clone)]
pub struct FPrint;
impl FPrint {
pub fn new() -> crate::Result<FPrint> {
let res = unsafe { fprint_sys::fp_init() } as i32;
if res == 0 {
Ok(FPrint)
} else {
Err(crate::FPrintError::InitError(res))
}
}
pub fn discover(&self) -> crate::Result<DiscoveredDevices> {
let devices_list = unsafe { fprint_sys::fp_discover_devs() };
if devices_list.is_null() {
Err(crate::FPrintError::NullPtr(
crate::NullPtrContext::Discovering,
))
} else {
DiscoveredDevices::new(devices_list)
}
}
}
impl Drop for FPrint {
fn drop(&mut self) {
unsafe {
fprint_sys::fp_exit();
}
}
}