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

pub trait StrExt {
    fn splitn_exact<'a, P: Into<AltPattern<'a>>>(
        &'a self,
        n: usize,
        pat: P
    ) -> Option<Vec<&'a str>>; }

Extension trait with useful methods for primitive type str.

Required methods

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());
Loading content...

Implementations on Foreign Types

impl<'_> StrExt for &'_ str[src]

Loading content...

Implementors

Loading content...