[][src]Struct hexavalent::hook::HookHandle

pub struct HookHandle { /* fields omitted */ }

A handle to a hook registered with HexChat.

Cannot be constructed in user code, but is returned from hook registration functions such as PluginHandle::hook_command.

Can be passed to PluginHandle::unhook to unregister the hook.

HexChat automatically unhooks any remaining hooks after your plugin finishes unloading, so this type is only useful if you need to unhook a hook while your plugin is running.

Examples

use std::cell::Cell;
use hexavalent::{Plugin, PluginHandle};
use hexavalent::hook::{Eat, HookHandle, Priority};

#[derive(Default)]
struct MyPlugin {
    cmd_handle: Cell<Option<HookHandle>>,
}

impl Plugin for MyPlugin {
    fn init(&self, ph: PluginHandle<'_, Self>) {
        let hook = ph.hook_command(
            "theCommand\0",
            "Usage: THECOMMAND, can be disabled\0",
            Priority::Normal,
            |plugin, ph, words| {
                ph.print("Yep, it still works.\0");
                Eat::All
            }
        );
        self.cmd_handle.set(Some(hook));

        ph.hook_command(
            "disableTheCommand\0",
            "Usage: DISABLETHECOMMAND, disables /theCommand\0",
            Priority::Normal,
            |plugin, ph, words| {
                match plugin.cmd_handle.take() {
                    Some(hook) => {
                        ph.unhook(hook);
                        ph.print("Disabled the command!\0");
                    }
                    None => {
                        ph.print("Command already disabled!\0");
                    }
                }
                Eat::All
            }
        );
    }
}

Trait Implementations

impl Debug for HookHandle[src]

Auto Trait Implementations

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.