The code example you give contains a few syntactic errors, and you could also do a better job providing the full error message. It’d be easiest to help you if you provided the full error message together with a complete code example so that we can reproduce that error message ourselves. I’m also not quite sure if what you want to achieve is entirely in line with the kind of code you’ve written here—not that
trim_matches only removes parts of the string that are in the beginning or the end of the string, not in the middle.
Anyways, the argument to
trim_matches can be a function from
bool, you’re trying to combine two such functions here
char::is_numeric and you can’t do that with
& the way you’re trying to do. You’d need to create a new function, or a closure here, also you probably want a disjunction (logical OR-operation) instead of a conjunction (logical AND-operation), because AFAIK no character would be both
numeric. Try something like
s.trim_matches(|c| c.is_alphabetic() || c.is_numeric());
|c| c.is_alphabetic() || c.is_numeric() is a closure that takes an argument
c (which is inferret to be of type
char) and returns a boolean. The inner expression
c.is_alphabetic() || c.is_numeric() is of type bool and uses the argument
c. It’s using method-call syntax and is equivalent to something like
char::is_alphabetic(c) || char::is_numeric(c). The
|| operator is a logical “OR” operation.