pub struct FdHook<F> { /* private fields */ }
Expand description
Hook for a file descriptor, the hook is removed when the object is dropped.
Implementations§
Source§impl<F> FdHook<F>
impl<F> FdHook<F>
Sourcepub fn new(
fd_object: F,
mode: FdHookMode,
callback: impl FdHookCallback<FdObject = F> + 'static,
) -> Result<FdHook<F>, ()>where
F: AsRawFd,
pub fn new(
fd_object: F,
mode: FdHookMode,
callback: impl FdHookCallback<FdObject = F> + 'static,
) -> Result<FdHook<F>, ()>where
F: AsRawFd,
Hook an object that can be turned into a raw file descriptor. Returns the hook object.
§Arguments
-
fd_object
- An object for wich the file descriptor will be watched and the callback called when read or write operations can happen on it. -
mode
- Configure the hook to watch for writes, reads or both on the file descriptor. -
callback
- A function that will be called if a watched event on the file descriptor happends. -
callback_data
- Data that will be passed to the callback every time the callback runs. This data will be freed when the hook is unhooked.
§Panics
Panics if the method is not called from the main Weechat thread.
§Example
struct Data;
impl FdHookCallback for Data {
type FdObject = Receiver<String>;
fn callback(&mut self, _: &Weechat, receiver: &mut Receiver<String>) {
if let Ok(data) = receiver.recv() {
Weechat::print(&data)
}
}
}
let (sender, receiver): (Sender<String>, Receiver<String>) = channel();
let hook = FdHook::new(receiver, FdHookMode::Read, Data)
.expect("Can't create executor FD hook");
Auto Trait Implementations§
impl<F> Freeze for FdHook<F>
impl<F> !RefUnwindSafe for FdHook<F>
impl<F> !Send for FdHook<F>
impl<F> !Sync for FdHook<F>
impl<F> Unpin for FdHook<F>
impl<F> !UnwindSafe for FdHook<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more