Trait stdext::str::StrExt[][src]

pub trait StrExt {
    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

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

Implementations on Foreign Types

Implementors