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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![warn(missing_docs)]
extern crate libc;
extern crate libudev_sys as ffi;
pub use device::{Attribute, Attributes, Device, Properties, Property};
pub use enumerator::{Devices, Enumerator};
pub use error::{Error, Kind as ErrorKind, Result};
pub use monitor::{Builder as MonitorBuilder, Event, EventType, Socket as MonitorSocket};
macro_rules! try_alloc {
($exp:expr) => {{
let ptr = $exp;
if ptr.is_null() {
return Err(::error::from_errno(::libc::ENOMEM));
}
ptr
}};
}
pub trait AsRaw<T: 'static> {
fn as_raw(&self) -> *mut T;
fn into_raw(self) -> *mut T;
}
pub trait FromRaw<T: 'static> {
unsafe fn from_raw(ptr: *mut T) -> Self;
}
macro_rules! as_ffi {
($struct_:ident, $field:ident, $type_:ty) => {
impl $crate::AsRaw<$type_> for $struct_ {
fn as_raw(&self) -> *mut $type_ {
self.$field
}
fn into_raw(self) -> *mut $type_ {
self.$field
}
}
impl $crate::FromRaw<$type_> for $struct_ {
unsafe fn from_raw(t: *mut $type_) -> Self {
Self { $field: t }
}
}
};
}
mod device;
mod enumerator;
mod error;
mod monitor;
mod util;