1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use crate::*;
/// Win32 handle types implement this trait to simplify error handling.
pub unsafe trait Handle: Sized + PartialEq {
fn is_invalid(&self) -> bool {
*self == unsafe { std::mem::zeroed() }
}
fn ok(self) -> Result<Self> {
if !self.is_invalid() {
Ok(self)
} else {
Err(Error::from_win32())
}
}
}