use pasts::prelude::*;
use whisk::Channel;
use crate::{kind::DeviceKind, OsDevice, Platform, Watch};
#[derive(Debug)]
pub struct Device {
pub(crate) channel: Channel,
pub(crate) kind: DeviceKind,
}
impl Device {
#[allow(unreachable_code, unused_variables)]
pub fn new(fd: impl Into<OsDevice>, watch: Watch) -> Self {
let kind = fd.into().into();
let channel = Platform::watch(&kind, watch);
Self { channel, kind }
}
}
impl Notify for Device {
type Event = ();
fn poll_next(mut self: Pin<&mut Self>, task: &mut Task<'_>) -> Poll {
Pin::new(&mut self.channel).poll_next(task)
}
}
impl Drop for Device {
fn drop(&mut self) {
Platform::unwatch(&self.kind);
}
}