Struct hexchat_unsafe_plugin::ValidContext
source · [−]pub struct ValidContext<'a, 'ph: 'a> { /* private fields */ }
Expand description
A PluginHandle operating on a valid context.
This mechanism attempts to reduce the likelihood of segfaults in hexchat code.
See also PluginHandle::ensure_valid_context
.
Implementations
sourceimpl<'a, 'ph: 'a> ValidContext<'a, 'ph>
impl<'a, 'ph: 'a> ValidContext<'a, 'ph>
sourcepub fn find_context(
&self,
servname: Option<&str>,
channel: Option<&str>
) -> Option<Context<'ph>>
pub fn find_context(
&self,
servname: Option<&str>,
channel: Option<&str>
) -> Option<Context<'ph>>
Finds an open context for the given servname and channel.
sourcepub fn nickcmp(&self, nick1: &str, nick2: &str) -> Ordering
pub fn nickcmp(&self, nick1: &str, nick2: &str) -> Ordering
Compares two nicks based on the server’s case mapping.
pub fn send_modes<'b, I: IntoIterator<Item = &'b str>>(
&mut self,
iter: I,
mpl: i32,
sign: char,
mode: char
)
sourcepub fn command(self, cmd: &str)
pub fn command(self, cmd: &str)
Executes a command.
Examples
use hexchat_unsafe_plugin::{ValidContext};
fn join(context: ValidContext<'_, '_>, channel: &str) {
context.command(&format!("join {}", channel));
}
sourcepub fn emit_print<'b, I: IntoIterator<Item = &'b str>>(
self,
event: &str,
args: I
) -> bool
pub fn emit_print<'b, I: IntoIterator<Item = &'b str>>(
self,
event: &str,
args: I
) -> bool
Prints an event message, and returns a success status (whether or not the event exists).
Examples
use hexchat_unsafe_plugin::{ValidContext};
fn emit_channel_message(context: ValidContext<'_, '_>, nick: &str, msg: &str) {
context.emit_print("Channel Message", [nick, msg]);
}
sourcepub fn emit_print_attrs<'b, I: IntoIterator<Item = &'b str>>(
self,
attrs: EventAttrs<'_>,
event: &str,
args: I
) -> bool
pub fn emit_print_attrs<'b, I: IntoIterator<Item = &'b str>>(
self,
attrs: EventAttrs<'_>,
event: &str,
args: I
) -> bool
Prints an event message, and returns a success status (whether or not the event exists).
Also allows setting event attributes.
Examples
use std::time::SystemTime;
use hexchat_unsafe_plugin::{EventAttrs, ValidContext};
fn emit_channel_message_at(context: ValidContext<'_, '_>, time: Option<SystemTime>, nick: &str, msg: &str) {
let mut attrs = EventAttrs::new();
attrs.server_time = time;
context.emit_print_attrs(attrs, "Channel Message", [nick, msg]);
}
sourcepub fn get_context(&self) -> Context<'ph>
pub fn get_context(&self) -> Context<'ph>
Returns the current context.
sourcepub fn set_context(&mut self, ctx: &Context<'ph>) -> bool
pub fn set_context(&mut self, ctx: &Context<'ph>) -> bool
Sets the current context.
Returns true
if the context is valid, false
otherwise.
sourcepub fn print<T: ToString>(&self, s: T)
pub fn print<T: ToString>(&self, s: T)
Prints to the hexchat buffer.
See PluginHandle::print
.
sourcepub fn write_fmt(&self, fmt: Arguments<'_>)
pub fn write_fmt(&self, fmt: Arguments<'_>)
sourcepub fn hook_command<'f, F>(
&self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_command<'f, F>(
&self,
cmd: &str,
pri: i32,
help: Option<&str>,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a command hook.
sourcepub fn hook_server<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_server<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a server hook.
sourcepub fn hook_server_attrs<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_server_attrs<'f, F>(
&self,
cmd: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, WordEol<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a server hook with attributes.
sourcepub fn hook_print<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_print<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a print hook.
sourcepub fn hook_print_attrs<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_print_attrs<'f, F>(
&self,
name: &str,
pri: i32,
cb: F
) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>, Word<'_>, EventAttrs<'_>) -> Eat + 'f + RefUnwindSafe,
'f: 'ph,
Sets a print hook with attributes.
sourcepub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe,
'f: 'ph,
pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where
F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe,
'f: 'ph,
Sets a timer hook.
sourcepub fn get_info<'b>(&'b self, id: InfoId<'_>) -> Option<Cow<'b, str>>
pub fn get_info<'b>(&'b self, id: InfoId<'_>) -> Option<Cow<'b, str>>
Returns context and client information.
sourcepub fn get_libdirfs(&self) -> Option<CString>
pub fn get_libdirfs(&self) -> Option<CString>
Returns the plugin directory.
Auto Trait Implementations
impl<'a, 'ph> RefUnwindSafe for ValidContext<'a, 'ph>
impl<'a, 'ph> !Send for ValidContext<'a, 'ph>
impl<'a, 'ph> !Sync for ValidContext<'a, 'ph>
impl<'a, 'ph> Unpin for ValidContext<'a, 'ph> where
'ph: 'a,
impl<'a, 'ph> !UnwindSafe for ValidContext<'a, 'ph>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more