This is an archive of the discontinued Mercurial Phabricator instance.

rust-matchers: improve `Matcher` trait ergonomics
ClosedPublic

Authored by Alphare on Nov 29 2019, 12:56 PM.

Details

Summary

VisitChildrenSet has no need to own the set, this will save allocations.

The file_set return type change is motivated by both ergonomics and... being
able to compile code.
The AlwaysMatcher does not store a file_set, which requires it to return an
owned HashSet, which in turn would change our return type to Cow<&HgPath>
(lifetimes omitted). This is both un-ergonomic and troublesome for more
complex lifetime issues (especially with the upcoming FileMatcher in the
following patch).

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Alphare created this revision.Nov 29 2019, 12:56 PM
kevincox accepted this revision.Dec 2 2019, 8:09 AM
kevincox added inline comments.
rust/hg-core/src/matchers.rs
87

Another option here would just to have a global empty hash set.

Alphare added inline comments.Dec 2 2019, 9:20 AM
rust/hg-core/src/matchers.rs
87

I feel like an Option is more explicit and less contrived, but yes.

pulkit accepted this revision.Dec 10 2019, 10:13 AM
This revision is now accepted and ready to land.Dec 10 2019, 10:13 AM
This revision was automatically updated to reflect the committed changes.