sorry, this memo is in pretty bad shape ..
generalize prints over std::str::pattern::Pattern (like in String::contains) https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html
Currently the Pattern is only implemented for String
and str
and is
not yet stabilized (#27721)
for 3rd party implementations. But once it is stabilized, you would have
regex support and the like for free. :-)
I'm not sure if Rust would accept
fn prints<T, O>(self, output: O) -> Self where
O: Into<T>,
T: Pattern
That would be ambiguous in cases where a type X
implements Into<A>
and
Into<B>
, where A: Pattern, B: Pattern
. You would then probably need to
disambiguate prints(x as Into<A>)
or prints::<A, _>(x)
. Even if Rust
accepted it, it would introduce some forward compatibility hazards, where
adding impls X: Into<B>
and B: Pattern
would make code in other places
suddenly be ambiguous.
So my conclusion is, it should be either prints<O: Into<String>>
or
prints<O: Pattern>
.
In the spirit of the above patterns, might be assertions like this:
- print_starts_with
- print_ends_with
@killercup: sorry about the memos being in bad shape - just tell me if you have any questions. And I'll try to make sense of them again myself. :-)