diff options
Diffstat (limited to 'src/pluginfo.rs')
-rw-r--r-- | src/pluginfo.rs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/pluginfo.rs b/src/pluginfo.rs index 195aa26..507751a 100644 --- a/src/pluginfo.rs +++ b/src/pluginfo.rs @@ -1,5 +1,5 @@ // This file is part of Hexchat Plugin API Bindings for Rust -// Copyright (C) 2018, 2021 Soni L. +// Copyright (C) 2018, 2021, 2022 Soni L. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as @@ -36,13 +36,19 @@ impl PluginInfo { /// /// # Safety /// - /// This function is unsafe, as it can't guarantee the validity of its arguments. It does more - /// checking than `new_unchecked` however. + /// This function is unsafe, as it can't guarantee the validity of its + /// arguments. It does more checking than `new_unchecked` however. + /// + /// See `new_unchecked` for the full requirements. /// /// # Panics /// /// This function explicitly doesn't panic. Call unwrap() on the result instead. - pub unsafe fn new(name: *mut *const libc::c_char, desc: *mut *const libc::c_char, vers: *mut *const libc::c_char) -> Option<PluginInfo> { + pub unsafe fn new( + name: *mut *const libc::c_char, + desc: *mut *const libc::c_char, + vers: *mut *const libc::c_char, + ) -> Option<PluginInfo> { if name.is_null() || desc.is_null() || vers.is_null() || name == desc || desc == vers || name == vers { None } else { @@ -54,9 +60,14 @@ impl PluginInfo { /// /// # Safety /// - /// This function is unsafe, as it doesn't check the validity of the arguments. You're expected - /// to only pass in non-aliased non-null pointers. Use new if unsure. - pub unsafe fn new_unchecked(name: *mut *const libc::c_char, desc: *mut *const libc::c_char, vers: *mut *const libc::c_char) -> PluginInfo { + /// This function is unsafe, as it doesn't check the validity of the + /// arguments. You're expected to only pass in non-aliased non-null valid + /// pointers. Use `new` if unsure. + pub unsafe fn new_unchecked( + name: *mut *const libc::c_char, + desc: *mut *const libc::c_char, + vers: *mut *const libc::c_char, + ) -> PluginInfo { PluginInfo { name, desc, vers } @@ -84,5 +95,19 @@ impl PluginInfo { *self.vers = cstr(EMPTY_CSTRING_DATA); } } + + /// Returns whether this `PluginInfo` has been registered. + /// + /// # Safety + /// + /// We cannot currently guarantee the validity of the pointers contained in + /// here. + pub unsafe fn is_registered(&self) -> bool { + ![ + self.name, + self.desc, + self.vers, + ].into_iter().any(|meta| unsafe { *meta }.is_null()) + } } |