#![warn(missing_docs)]
extern crate io_lifetimes;
extern crate libc;
pub extern crate libudev_sys as ffi;
#[cfg(feature = "mio06")]
pub extern crate mio06 as mio;
#[cfg(feature = "mio07")]
pub extern crate mio07 as mio;
#[cfg(feature = "mio08")]
pub extern crate mio08 as mio;
#[cfg(feature = "mio10")]
pub extern crate mio10 as mio;
pub use device::{Attributes, Device, DeviceType, Properties};
pub use enumerator::{Devices, Enumerator};
#[cfg(feature = "hwdb")]
pub use hwdb::Hwdb;
pub use list::{Entry, List};
pub use monitor::{
Builder as MonitorBuilder, Event, EventType, Socket as MonitorSocket,
SocketIter as MonitorSocketIter,
};
pub use udev::Udev;
macro_rules! try_alloc {
($exp:expr) => {{
let ptr = $exp;
if ptr.is_null() {
return Err(std::io::Error::last_os_error());
}
ptr
}};
}
pub trait AsRaw<T: 'static> {
fn as_raw(&self) -> *mut T;
fn into_raw(self) -> *mut T;
}
pub trait AsRawWithContext<T: 'static> {
fn as_raw(&self) -> *mut T;
fn udev(&self) -> &Udev;
fn into_raw_with_context(self) -> (*mut ffi::udev, *mut T);
}
pub trait FromRaw<T: 'static> {
unsafe fn from_raw(ptr: *mut T) -> Self;
}
pub trait FromRawWithContext<T: 'static> {
unsafe fn from_raw_with_context(udev: *mut ffi::udev, ptr: *mut T) -> Self;
}
macro_rules! as_ffi {
($struct_:ident, $field:ident, $type_:ty, $ref:path) => {
as_raw!($struct_, $field, $type_, $ref);
from_raw!($struct_, $field, $type_);
};
}
macro_rules! as_ffi_with_context {
($struct_:ident, $field:ident, $type_:ty, $ref:path) => {
as_raw_with_context!($struct_, $field, $type_, $ref);
from_raw_with_context!($struct_, $field, $type_);
};
}
macro_rules! as_raw {
($struct_:ident, $field:ident, $type_:ty, $ref:path) => {
impl $crate::AsRaw<$type_> for $struct_ {
fn as_raw(&self) -> *mut $type_ {
self.$field
}
fn into_raw(self) -> *mut $type_ {
unsafe { $ref(self.$field) };
self.$field
}
}
};
}
macro_rules! from_raw {
($struct_:ident, $field:ident, $type_:ty) => {
impl $crate::FromRaw<$type_> for $struct_ {
unsafe fn from_raw(t: *mut $type_) -> Self {
Self { $field: t }
}
}
};
}
macro_rules! as_raw_with_context {
($struct_:ident, $field:ident, $type_:ty, $ref:path) => {
impl $crate::AsRawWithContext<$type_> for $struct_ {
fn as_raw(&self) -> *mut $type_ {
self.$field
}
fn udev(&self) -> &Udev {
&self.udev
}
fn into_raw_with_context(self) -> (*mut ffi::udev, *mut $type_) {
let udev = self.udev.as_raw();
unsafe { ffi::udev_ref(udev) };
unsafe { $ref(self.$field) };
(udev, self.$field)
}
}
};
}
macro_rules! from_raw_with_context {
($struct_:ident, $field:ident, $type_:ty) => {
impl $crate::FromRawWithContext<$type_> for $struct_ {
unsafe fn from_raw_with_context(udev: *mut ffi::udev, t: *mut $type_) -> Self {
Self {
udev: Udev::from_raw(udev),
$field: t,
}
}
}
};
}
mod device;
mod enumerator;
#[cfg(feature = "hwdb")]
mod hwdb;
mod list;
mod monitor;
mod udev;
mod util;