D7178: [RFC] rust-matchers: add `Matcher` trait and implement `AlwaysMatcher`

Yuya Nishihara yuya at tcha.org
Wed Nov 6 07:14:31 EST 2019


> +pub trait Matcher {
> +    /// Explicitly listed files
> +    fn file_set(&self) -> HashSet<&HgPath>;

[...]
> +    /// Matcher will match everything and `files_set()` will be empty:
> +    /// optimization might be possible.
> +    fn matches_everything(&self) -> bool {
> +        false
> +    }

Maybe better to not provide the default implementations since not a few
matchers will have to reimplement them.

> +impl Matcher for AlwaysMatcher {
> +    fn file_set(&self) -> HashSet<&HgPath> {
> +        HashSet::new()
> +    }
> +
> +    fn visit_children_set(
> +        &self,
> +        _directory: impl AsRef<HgPath>,
> +    ) -> VisitChildrenSet {
> +        VisitChildrenSet::Recursive
> +    }

Need to implement `matches()` and `matches_everything()`?


More information about the Mercurial-devel mailing list