You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove the need for allocation from is_utf8_string.
Previously, `IsEncodedStringMatcher` converted its actual value input to
a `Vec` and constructed a `String` out of that in order to match it.
This is because using a string slice caused problems with the borrow
checker as described in #323.
The fundamental problem is that the type against which the inner matcher
is matching is a reference whose lifetime must be named in the trait
bound:
```
impl<ActualT: AsRef<[u8]> + Debug, InnerMatcherT> Matcher
for IsEncodedStringMatcher<ActualT, InnerMatcherT>
where
InnerMatcherT: Matcher<ActualT = &'what str>,
^^^^ What goes here???
```
One option is just to remove the reference:
```
impl<ActualT: AsRef<[u8]> + Debug, InnerMatcherT> Matcher
for IsEncodedStringMatcher<ActualT, InnerMatcherT>
where
InnerMatcherT: Matcher<ActualT = str>,
```
This doesn't work when the inner matcher is `eq`, since one would then
be comparing an `str` and a string slice:
```
verify_that!("A string".as_bytes(), is_utf8_string(eq("A string"))) // Compile error: cannot compare str and &str
```
However, this problem does not occur with `StrMatcher`:
```
verify_that!("A string".as_bytes(), is_utf8_string(constains_substring("A string"))) // Passes
```
So this also introduces an easy way to obtain a `StrMatcher` to check
string equality:
```
verify_that!("A string".as_bytes(), is_utf8_string(eq_str("A string"))) // Passes
```
This is slightly inconvenient, since one must use a different matcher
to compare string equality in this case. But it is well-documented and
not too inconvenient to use. So it should be okay.
0 commit comments