Function str_concat::concat[][src]

pub fn concat<'a>(a: &'a str, b: &'a str) -> Result<&'a str, Error>

Concatenate two string slices if they are adjacent.

If two strs are adjacent to each other in memory, this function concatenates both, creating a single str.

Errors

Returns Err if the two slices aren't adjacent, a is after b, or if a is too long for proper concatenation (longer than isize::MAX).

Examples

Correct usage:

let s = "0123456789";
assert_eq!("0123456", concat(&s[..5], &s[5..7]).unwrap());

Non-adjacent string slices:

let s = "0123456789";
assert_eq!(Err(Error::NotAdjacent), concat(&s[..5], &s[6..7]))