Skip to content

Commit e8a737a

Browse files
committed
use newtype for glob::Pattern as well
1 parent 8386600 commit e8a737a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/sudoers/tokens.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,15 @@ pub type Command = (SimpleCommand, Option<Box<[String]>>);
168168

169169
/// A type that is specific to 'only commands', that can only happen in "Defaults!command" contexts;
170170
/// which is essentially a subset of "Command"
171-
#[cfg(feature = "rust-glob")]
172-
pub type SimpleCommand = glob::Pattern;
173-
#[cfg(not(feature = "rust-glob"))]
174-
pub struct SimpleCommand(SudoString);
171+
pub struct SimpleCommand(<SimpleCommand as std::ops::Deref>::Target);
175172

176-
#[cfg(not(feature = "rust-glob"))]
177173
impl std::ops::Deref for SimpleCommand {
174+
#[cfg(feature = "rust-glob")]
175+
type Target = glob::Pattern;
176+
#[cfg(not(feature = "rust-glob"))]
178177
type Target = SudoString;
179178

180-
fn deref(&self) -> &SudoString {
179+
fn deref(&self) -> &Self::Target {
181180
&self.0
182181
}
183182
}
@@ -238,7 +237,9 @@ impl Token for SimpleCommand {
238237
fn construct(mut cmd: String) -> Result<Self, String> {
239238
#[cfg(feature = "rust-glob")]
240239
let make_pattern = |pat: String| {
241-
glob::Pattern::new(&pat).map_err(|err| format!("wildcard pattern error {err}"))
240+
glob::Pattern::new(&pat)
241+
.map(SimpleCommand)
242+
.map_err(|_| "wildcard pattern error".to_string())
242243
};
243244

244245
#[cfg(not(feature = "rust-glob"))]

0 commit comments

Comments
 (0)