Repository: sharkdp/fd
File: src/internal.rs (Rust)

Code before:
    pub fn is_within(&self, size: u64) -> bool {
        match self {
            &SizeFilter::Max(limit) => size <= limit,
            &SizeFilter::Min(limit) => size >= limit,
        }
    }
}

/// Filter based on time ranges
#[derive(Debug, PartialEq)]
pub enum TimeFilter {
    Before(SystemTime),
    After(SystemTime),
}

impl TimeFilter {
    fn from_str(s: &str) -> Option<SystemTime> {
        use humantime;
        humantime::parse_duration(s)
            .map(|duration| SystemTime::now() - duration)
            .or_else(|_| humantime::parse_rfc3339_weak(s))
            .ok()
    }

    pub fn before(s: &str) -> Option<TimeFilter> {
        Some(TimeFilter::Before(TimeFilter::from_str(s)?))
    }

    pub fn after(s: &str) -> Option<TimeFilter> {
        Some(TimeFilter::After(TimeFilter::from_str(s)?))
    }

    pub fn is_within(&self, t: &SystemTime) -> bool {
        match self {
            TimeFilter::Before(limit) => t <= limit,
            TimeFilter::After(limit) => t >= limit,
        }
    }
}

/// Configuration options for *fd*.
pub struct FdOptions {
    /// Whether the search is case-sensitive or case-insensitive.
    pub case_sensitive: bool,

    /// Whether to search within the full file path or just the base name (filename or directory
    /// name).
    pub search_full_path: bool,

    /// Whether to ignore hidden files and directories (or not).
    pub ignore_hidden: bool,

Review comment (suggestion):
Alternative implementation:
``` rust
TimeFilter::from_str(s).map(TimeFilter::Before)
```
Choose whichever you prefer :smile:. I was just shortly confused because I hadn't seen the `?`.

Code after:
    pub fn is_within(&self, size: u64) -> bool {
        match self {
            &SizeFilter::Max(limit) => size <= limit,
            &SizeFilter::Min(limit) => size >= limit,
        }
    }
}

/// Filter based on time ranges
#[derive(Debug, PartialEq)]
pub enum TimeFilter {
    Before(SystemTime),
    After(SystemTime),
}

impl TimeFilter {
    fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> {
        use humantime;
        humantime::parse_duration(s)
            .map(|duration| *ref_time - duration)
            .or_else(|_| humantime::parse_rfc3339_weak(s))
            .ok()
    }

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

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

    pub fn applies_to(&self, t: &SystemTime) -> bool {
        match self {
            TimeFilter::Before(limit) => t <= limit,
            TimeFilter::After(limit) => t >= limit,
        }
    }
}

/// Configuration options for *fd*.
pub struct FdOptions {
    /// Whether the search is case-sensitive or case-insensitive.
    pub case_sensitive: bool,

    /// Whether to search within the full file path or just the base name (filename or directory
    /// name).
    pub search_full_path: bool,

    /// Whether to ignore hidden files and directories (or not).
    pub ignore_hidden: bool,