pub trait StrExt {
// Required method
fn splitn_exact<'a, P: Into<AltPattern<'a>>>(
&'a self,
n: usize,
pat: P,
) -> Option<Vec<&'a str>>;
}Expand description
Extension trait with useful methods for primitive type str.
Required Methods§
Sourcefn splitn_exact<'a, P: Into<AltPattern<'a>>>(
&'a self,
n: usize,
pat: P,
) -> Option<Vec<&'a str>>
fn splitn_exact<'a, P: Into<AltPattern<'a>>>( &'a self, n: usize, pat: P, ) -> Option<Vec<&'a str>>
Version of str::splitn which expects the exact
amount of entries obtained after splitting. This method
returns Vec, as SplitN iterator depends on the unstable
type Pattern and cannot be returned on the stable Rust.
§Examples
use stdext::prelude::*;
let data = "Hello world";
let splitted = data.splitn_exact(2, " ").unwrap();
assert_eq!(&splitted, &["Hello", "world"]);
let splitted = data.splitn_exact(5, '-');
assert!(splitted.is_none());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.