Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ impl clap::FromArgMatches for Exec {
})
.transpose()
.map_err(|e| clap::Error::raw(ErrorKind::InvalidValue, e))?;
Ok(Exec { command })
Ok(Self { command })
}

fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::error::Result<()> {
Expand Down
12 changes: 6 additions & 6 deletions src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ pub struct CommandSet {
}

impl CommandSet {
pub fn new<I, T, S>(input: I) -> Result<CommandSet>
pub fn new<I, T, S>(input: I) -> Result<Self>
where
I: IntoIterator<Item = T>,
T: IntoIterator<Item = S>,
S: AsRef<str>,
{
Ok(CommandSet {
Ok(Self {
mode: ExecutionMode::OneByOne,
commands: input
.into_iter()
Expand All @@ -48,13 +48,13 @@ impl CommandSet {
})
}

pub fn new_batch<I, T, S>(input: I) -> Result<CommandSet>
pub fn new_batch<I, T, S>(input: I) -> Result<Self>
where
I: IntoIterator<Item = T>,
T: IntoIterator<Item = S>,
S: AsRef<str>,
{
Ok(CommandSet {
Ok(Self {
mode: ExecutionMode::Batch,
commands: input
.into_iter()
Expand Down Expand Up @@ -220,7 +220,7 @@ struct CommandTemplate {
}

impl CommandTemplate {
fn new<I, S>(input: I) -> Result<CommandTemplate>
fn new<I, S>(input: I) -> Result<Self>
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
Expand Down Expand Up @@ -250,7 +250,7 @@ impl CommandTemplate {
args.push(FormatTemplate::Tokens(vec![Token::Placeholder]));
}

Ok(CommandTemplate { args })
Ok(Self { args })
}

fn number_of_tokens(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions src/exit_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl From<ExitCode> for i32 {
fn from(code: ExitCode) -> Self {
match code {
ExitCode::Success => 0,
ExitCode::HasResults(has_results) => !has_results as i32,
ExitCode::HasResults(has_results) => !has_results as Self,
ExitCode::GeneralError => 1,
ExitCode::KilledBySigint => 130,
}
Expand All @@ -30,7 +30,7 @@ impl ExitCode {
/// Exit the process with the appropriate code.
pub fn exit(self) -> ! {
#[cfg(unix)]
if self == ExitCode::KilledBySigint {
if self == Self::KilledBySigint {
// Get rid of the SIGINT handler, if present, and raise SIGINT
unsafe {
if signal(Signal::SIGINT, SigHandler::SigDfl).is_ok() {
Expand Down
16 changes: 8 additions & 8 deletions src/filter/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Check<T> {
}

impl OwnerFilter {
const IGNORE: Self = OwnerFilter {
const IGNORE: Self = Self {
uid: Check::Ignore,
gid: Check::Ignore,
};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl OwnerFilter {
}
})?;

Ok(OwnerFilter { uid, gid })
Ok(Self { uid, gid })
}

/// If self is a no-op (ignore both uid and gid) then return `None`, otherwise wrap in a `Some`
Expand All @@ -76,9 +76,9 @@ impl OwnerFilter {
impl<T: PartialEq> Check<T> {
fn check(&self, v: T) -> bool {
match self {
Check::Equal(x) => v == *x,
Check::NotEq(x) => v != *x,
Check::Ignore => true,
Self::Equal(x) => v == *x,
Self::NotEq(x) => v != *x,
Self::Ignore => true,
}
}

Expand All @@ -87,16 +87,16 @@ impl<T: PartialEq> Check<T> {
F: Fn(&str) -> Result<T>,
{
let (s, equality) = match s {
Some("") | None => return Ok(Check::Ignore),
Some("") | None => return Ok(Self::Ignore),
Some(s) if s.starts_with('!') => (&s[1..], false),
Some(s) => (s, true),
};

f(s).map(|x| {
if equality {
Check::Equal(x)
Self::Equal(x)
} else {
Check::NotEq(x)
Self::NotEq(x)
}
})
}
Expand Down
14 changes: 7 additions & 7 deletions src/filter/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TEBI: u64 = GIBI * 1024;

impl SizeFilter {
pub fn from_string(s: &str) -> anyhow::Result<Self> {
SizeFilter::parse_opt(s)
Self::parse_opt(s)
.ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", s))
}

Expand Down Expand Up @@ -58,18 +58,18 @@ impl SizeFilter {

let size = quantity * multiplier;
match limit_kind {
"+" => Some(SizeFilter::Min(size)),
"-" => Some(SizeFilter::Max(size)),
"" => Some(SizeFilter::Equals(size)),
"+" => Some(Self::Min(size)),
"-" => Some(Self::Max(size)),
"" => Some(Self::Equals(size)),
_ => None,
}
}

pub fn is_within(&self, size: u64) -> bool {
match *self {
SizeFilter::Max(limit) => size <= limit,
SizeFilter::Min(limit) => size >= limit,
SizeFilter::Equals(limit) => size == limit,
Self::Max(limit) => size <= limit,
Self::Min(limit) => size >= limit,
Self::Equals(limit) => size == limit,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/filter/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ impl TimeFilter {
}
}

pub fn before(s: &str) -> Option<TimeFilter> {
TimeFilter::from_str(s).map(TimeFilter::Before)
pub fn before(s: &str) -> Option<Self> {
Self::from_str(s).map(TimeFilter::Before)
}

pub fn after(s: &str) -> Option<TimeFilter> {
TimeFilter::from_str(s).map(TimeFilter::After)
pub fn after(s: &str) -> Option<Self> {
Self::from_str(s).map(TimeFilter::After)
}

pub fn applies_to(&self, t: &SystemTime) -> bool {
match self {
TimeFilter::Before(limit) => t < limit,
TimeFilter::After(limit) => t > limit,
Self::Before(limit) => t < limit,
Self::After(limit) => t > limit,
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ pub enum Token {
impl Display for Token {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Token::Placeholder => f.write_str("{}")?,
Token::Basename => f.write_str("{/}")?,
Token::Parent => f.write_str("{//}")?,
Token::NoExt => f.write_str("{.}")?,
Token::BasenameNoExt => f.write_str("{/.}")?,
Token::Text(ref string) => f.write_str(string)?,
Self::Placeholder => f.write_str("{}")?,
Self::Basename => f.write_str("{/}")?,
Self::Parent => f.write_str("{//}")?,
Self::NoExt => f.write_str("{.}")?,
Self::BasenameNoExt => f.write_str("{/.}")?,
Self::Text(ref string) => f.write_str(string)?,
}
Ok(())
}
Expand All @@ -52,7 +52,7 @@ static PLACEHOLDERS: OnceLock<AhoCorasick> = OnceLock::new();

impl FormatTemplate {
pub fn has_tokens(&self) -> bool {
matches!(self, FormatTemplate::Tokens(_))
matches!(self, Self::Tokens(_))
}

pub fn parse(fmt: &str) -> Self {
Expand Down Expand Up @@ -96,14 +96,14 @@ impl FormatTemplate {
}
if tokens.is_empty() {
// No placeholders were found, so just return the text
return FormatTemplate::Text(buf);
return Self::Text(buf);
}
// Add final text segment
if !buf.is_empty() {
tokens.push(Token::Text(buf));
}
debug_assert!(!tokens.is_empty());
FormatTemplate::Tokens(tokens)
Self::Tokens(tokens)
}

/// Generate a result string from this template. If path_separator is Some, then it will replace
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::path::{Path, PathBuf};
pub(crate) struct PathUrl(PathBuf);

impl PathUrl {
pub(crate) fn new(path: &Path) -> Option<PathUrl> {
Some(PathUrl(absolute_path(path).ok()?))
pub(crate) fn new(path: &Path) -> Option<Self> {
Some(Self(absolute_path(path).ok()?))
}
}

Expand Down