[][src]Function str_concat::concat_unordered

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

Concatenate two adjacent string slices no matter their order.

This is the same as concat except that it also concatenates b to a if b is in front of a (in which case concat errors).

Safety

The provided slices must come from the same underlying allocation. The adjacency test can not reliably differentiate between the one-past-the-end pointer of one allocation and the start of another. However, all slices must be within a single allocation.

Examples

Reversed order:

let s = "0123456789";
unsafe {
    // SAFETY: slices from the same str originally.
    assert_eq!("0123456", concat_unordered(&s[5..7], &s[..5]).unwrap());
}

Normal order:

let s = "0123456789";
unsafe {
    // SAFETY: slices from the same str originally.
    assert_eq!("0123456", concat_unordered(&s[..5], &s[5..7]).unwrap())
}