assert_fs icon indicating copy to clipboard operation
assert_fs copied to clipboard

assert(&Path) doesn't compile

Open SoniEx2 opened this issue 4 years ago • 4 comments

https://docs.rs/assert_fs/1.0.1/assert_fs/assert/trait.PathAssert.html#required-methods says you can pass a &Path, but this errors with:

error[E0277]: the trait bound `&Path: IntoPathPredicate<_>` is not satisfied
  --> src/git/tests.rs:54:36
   |
54 |         clone.child("HEAD").assert(repo.child("HEAD").path());
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPathPredicate<_>` is not implemented for `&Path`

SoniEx2 avatar Apr 22 '21 17:04 SoniEx2

I agree this would be convenient for validating against a "golden" file.

In predicates, this is exposed as a eq_file function, which will compare bytes. To compare a str, you do eq_file(path).str(). This doesn't address what if the user passed in (and intended) for directory comparisons.

With IntoPathPredicate, we can only choose one option, which do we go with? Whats the chance someone will be unhappily surprised and what will be the impact of that?

iirc one of the other concerns I previously had was the fact that we also support IntoPathPredicate for data (str, &[u8]). A str can be either the golden state or a path to the golden state, making the choice ambiguous, so I went all in on one to avoid using both and people assuming and being surprised by what a str might resolve to.

To be clear, none of this is to say "no", just sharing my thoughts in trying to weigh this out to see what other thoughts there are.

epage avatar Apr 23 '21 01:04 epage

Oh yeah hm... those are good points...

SoniEx2 avatar Apr 23 '21 10:04 SoniEx2

@epage I think the main problem here is less that "assert(&Path) doesn't work" and more that "The docs say it works but it doesn't." If you don't want to support assert(&Path) due to ambiguous interpretations, then the line in the docs about PathAssert accepting &Path should be removed.

jwodder avatar Dec 25 '23 12:12 jwodder

That reference in the docs has been removed.

epage avatar Dec 27 '23 18:12 epage