[][src]Struct weechat::hooks::FdHook

pub struct FdHook<F> { /* fields omitted */ }

Hook for a file descriptor, the hook is removed when the object is dropped.

Implementations

impl<F> FdHook<F>[src]

pub fn new(
    fd_object: F,
    mode: FdHookMode,
    callback: impl FdHookCallback<FdObject = F> + 'static
) -> Result<FdHook<F>, ()> where
    F: AsRawFd
[src]

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> !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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.