( )⚙ D9071 rust-matchers: make `Matcher` trait object-safe

This is an archive of the discontinued Mercurial Phabricator instance.

rust-matchers: make `Matcher` trait object-safe
ClosedPublic

Authored by Alphare on Sep 23 2020, 4:32 AM.

Details

Summary

Before this patch, it is not possible to create a Matcher trait-object (like
Box<dyn Matcher>), because of the use of a generic parameters in some methods,
namely impl AsRef<HgPath>.

While this makes the interface less flexible for callers in theory, it does not
change anything in the current codebase.

Until something like [1] is implemented, this is a "tradeoff" that we need to
make anyway.

[1] https://internals.rust-lang.org/t/pre-rfc-expand-object-safety/12693

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

Alphare created this revision.Sep 23 2020, 4:32 AM
marmoute accepted this revision.Sep 30 2020, 10:06 AM
marmoute added a subscriber: marmoute.

That seems fine to me. We can battle with rustc to re-introducing the genericity when we actually need it.

That seems fine to me. We can battle with rustc to re-introducing the genericity when we actually need it.

I don't think we ever will need to make it generic. However one of my (not so distant) future patches already needs to store a dyn Matcher in a struct.

martinvonz accepted this revision.Oct 1 2020, 12:50 AM
This revision is now accepted and ready to land.Oct 1 2020, 12:50 AM
This revision was automatically updated to reflect the committed changes.