pub struct CommandScope<T: ScopeObject> { /* private fields */ }
Expand description
Access scope for a command that can be retrieved directly in the command function.
Implementations§
Source§impl<T: ScopeObject> CommandScope<T>
impl<T: ScopeObject> CommandScope<T>
Source§impl<T: ScopeObjectMatch> CommandScope<T>
impl<T: ScopeObjectMatch> CommandScope<T>
Sourcepub fn matches(&self, input: &T::Input) -> bool
pub fn matches(&self, input: &T::Input) -> bool
Ensure all deny scopes were not matched and any allow scopes were.
This WILL return true
if the allow scopes are empty and the deny
scopes did not trigger. If you require at least one allow scope, then
ensure the allow scopes are not empty before calling this method.
if scope.allows().is_empty() {
return Err("you need to specify at least 1 allow scope!");
}
§Example
#[derive(Debug, Clone, Serialize, Deserialize)]
#[command]
fn my_command(scope: CommandScope<Scope>, input: String) -> Result<String, &'static str> {
if scope.matches(&input) {
do_work(input)
} else {
Err("Scope didn't match input")
}
}
Trait Implementations§
Source§impl<'a, R: Runtime, T: ScopeObject> CommandArg<'a, R> for CommandScope<T>
impl<'a, R: Runtime, T: ScopeObject> CommandArg<'a, R> for CommandScope<T>
Source§fn from_command(command: CommandItem<'a, R>) -> Result<Self, InvokeError>
fn from_command(command: CommandItem<'a, R>) -> Result<Self, InvokeError>
Grabs the ResolvedScope
from the CommandItem
and returns the associated CommandScope
.
Auto Trait Implementations§
impl<T> Freeze for CommandScope<T>
impl<T> RefUnwindSafe for CommandScope<T>where
T: RefUnwindSafe,
impl<T> Send for CommandScope<T>
impl<T> Sync for CommandScope<T>
impl<T> Unpin for CommandScope<T>
impl<T> UnwindSafe for CommandScope<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more