Crate stable_string_patterns_method

Crate stable_string_patterns_method 

Source
Expand description

This crates allows writing functions taking any type implementing std::str::pattern::Pattern on stable Rust.

This works by using a “proxy” trait, Searchable. Instead of depending on the unstable std::str::pattern::Pattern, you must use IntoSearchable as a bound in your code. This in turns lets you use the functions defined in StrPatternExt, which mimc the ones defined on str, except that they end with an underscore.

On top of the implementors of std::str::pattern::Pattern, the WhiteSpace type is also provided, with also implements IntoSearchable.

§Example

fn starts_and_ends_with(haystack: &str, p: impl IntoSearchable + Clone) -> bool {
    haystack.starts_with_(p.clone()) && haystack.ends_with_(p)
}

assert!(starts_and_ends_with("aa bb aa", "aa"));
assert!(starts_and_ends_with("aa bb aa", 'a'));
assert!(starts_and_ends_with("aa bb cc", ['a','c']));
assert!(starts_and_ends_with("\t bb  \n", WhiteSpace));

Structs§

WhiteSpace

Traits§

DoubleEndedSearchable
IntoSearchable
Searchable
StrPatternExt
The entry point of this crate