From b0dcbe6e3ee505009278826d0a9e651497c7182f Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Fri, 14 May 2021 22:06:23 -0300 Subject: Make print take ToString, so it's nicer to use --- src/lib.rs | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 444753e..465ff5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,19 @@ -/* - * Hexchat Plugin API Bindings for Rust - * Copyright (C) 2018 Soni L. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +// Hexchat Plugin API Bindings for Rust +// Copyright (C) 2018, 2021 Soni L. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + //! Write hexchat plugins in Rust! //! //! This library provides safe API bindings for hexchat, but doesn't attempt to fix hexchat's own @@ -954,9 +953,10 @@ impl PluginHandle { /// Prints to the hexchat buffer. // this checks the context internally. if it didn't, it wouldn't be safe to have here. - pub fn print(&mut self, s: &str) { + pub fn print(&mut self, s: T) { + let s = s.to_string(); unsafe { - hexchat_print_str(self.ph, s, true); + hexchat_print_str(self.ph, &*s, true); } } @@ -1186,7 +1186,7 @@ impl<'a> EnsureValidContext<'a> { /// Prints to the hexchat buffer. // as of hexchat 2.14.1, this does not call hooks. - pub fn print(&mut self, s: &str) { + pub fn print(&mut self, s: T) { self.ph.print(s) } @@ -1222,13 +1222,13 @@ impl<'a> EnsureValidContext<'a> { // mutable state, std provides std::sync::Mutex which has poisoning. Other interior mutability with // poisoning could also be used. std doesn't have anything for single-threaded performance (yet), // but hexchat isn't particularly performance-critical. -type CommandHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); +type CommandHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); /// Userdata type used by a server hook. -type ServerHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); +type ServerHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); /// Userdata type used by a print hook. -type PrintHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); +type PrintHookUd = (Box Eat + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo); /// Userdata type used by a timer hook. -type TimerHookUd = (Rc<(Box bool + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo)>, Rc>); +type TimerHookUd = (Rc<(Box bool + ::std::panic::RefUnwindSafe>, *mut internals::Ph, PluginInfo)>, Rc>); /// The contents of an empty CStr. /// @@ -1393,7 +1393,7 @@ impl PluginInfo { /// Plugin data stored in the hexchat plugin_handle. struct PhUserdata { - plug: Box, + plug: Box, pluginfo: PluginInfo, } -- cgit 1.4.1