[−][src]Function str_concat::concat_slice_unordered
pub unsafe fn concat_slice_unordered<'a, T>(
a: &'a [T],
b: &'a [T]
) -> Result<&'a [T], Error>
Concatenate two adjacent slices no matter their order.
This is the same as concat_slice
except that it also concatenates b
to
a
if b
is in front of a
(in which case of concat_slice
errors).
Keep in mind that slices of zero-sized types (ZST) will still not be concatenated.
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 = [0, 1, 2, 3, 4, 5, 6]; unsafe { // SAFETY: slices from the same bytes originally. assert_eq!( [0, 1, 2, 3, 4, 5, 6], concat_slice_unordered(&s[5..7], &s[..5]).unwrap()); }
Normal order:
let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; unsafe { // SAFETY: slices from the same bytes originally. assert_eq!( [0, 1, 2, 3, 4, 5, 6], concat_slice_unordered(&s[..5], &s[5..7]).unwrap()) }