Trait stdext::str::StrExt

source ·
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§

source

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());

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl StrExt for &str

source§

fn splitn_exact<'a, P: Into<AltPattern<'a>>>( &'a self, n: usize, pat: P ) -> Option<Vec<&'a str>>

Implementors§