I want to test a function that can accept a AsRef parameter, which can be call with &str or String, but I don't know the correct way to write it.
fn test<T, F>(fun: F) where T: AsRef<str>, F: Fn(T) -> bool {
assert_eq!(fun("abc"), true);
assert_eq!(fun("abc".to_string()), true);
}
fn is_ascii<T: AsRef<str>>(s: T) -> bool {
s.as_ref().is_ascii()
}
fn not_empty<T: AsRef<str>>(s: T) -> bool {
!s.as_ref().is_empty()
}
fn main() {
test(is_ascii);
test(not_empty);
}