Function rustc_data_structures::owned_slice::slice_owned

source ·
pub fn slice_owned<O, F>(owner: O, slicer: F) -> OwnedSlice
where O: Send + Sync + 'static, F: FnOnce(&O) -> &[u8],
Expand description

Makes an OwnedSlice out of an owner and a slicer function.

§Examples

let vec = vec![1, 2, 3, 4];

// Identical to slicing via `&v[1..3]` but produces an owned slice
let slice: OwnedSlice = slice_owned(vec, |v| &v[1..3]);
assert_eq!(&*slice, [2, 3]);
let vec = vec![1, 2, 3, 4];

// Identical to slicing via `&v[..]` but produces an owned slice
let slice: OwnedSlice = slice_owned(vec, Deref::deref);
assert_eq!(&*slice, [1, 2, 3, 4]);