Skip to content

Commit

Permalink
Get rid of an unnecessary clone in find_item
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jan 20, 2025
1 parent b411379 commit 3af49dd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sudoers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ where
{
let mut result = None;
for item in items {
let (judgement, who) = match item.clone().to_inner() {
let (judgement, who) = match item.as_inner() {
Qualified::Forbid(x) => (false, x),
Qualified::Allow(x) => (true, x),
};
let info = || item.to_info();
let info = || item.into_info();
match who {
Meta::All => result = judgement.then(info),
Meta::Only(ident) if matches(ident) => result = judgement.then(info),
Expand All @@ -413,29 +413,29 @@ where
trait WithInfo: Clone {
type Item;
type Info;
fn to_inner(self) -> Self::Item;
fn to_info(self) -> Self::Info;
fn as_inner(&self) -> Self::Item;
fn into_info(self) -> Self::Info;
}

/// A specific interface for `Spec<T>` --- we can't make a generic one;
/// A `Spec<T>` does not contain any additional information.
impl<'a, T> WithInfo for &'a Spec<T> {
type Item = &'a Spec<T>;
type Info = ();
fn to_inner(self) -> &'a Spec<T> {
fn as_inner(&self) -> &'a Spec<T> {
self
}
fn to_info(self) {}
fn into_info(self) {}
}

/// A commandspec can be "tagged"
impl<'a> WithInfo for (Tag, &'a Spec<Command>) {
type Item = &'a Spec<Command>;
type Info = Tag;
fn to_inner(self) -> &'a Spec<Command> {
fn as_inner(&self) -> &'a Spec<Command> {
self.1
}
fn to_info(self) -> Tag {
fn into_info(self) -> Tag {
self.0
}
}
Expand Down

0 comments on commit 3af49dd

Please sign in to comment.