pub trait SliceExt<T> {
// Required methods
fn to_vec_in2<A: Allocator>(&self, alloc: A) -> Vec<T, A>
where T: Clone;
fn repeat2(&self, n: usize) -> Vec<T, Global>
where T: Copy;
// Provided methods
fn to_vec(&self) -> Vec<T, Global>
where T: Clone { ... }
fn to_vec2(&self) -> Vec<T, Global>
where T: Clone { ... }
fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>
where T: Clone { ... }
fn repeat(&self, n: usize) -> Vec<T, Global>
where T: Copy { ... }
}Expand description
Slice methods that use Box and Vec from this crate.
Required Methods§
Sourcefn to_vec_in2<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
fn to_vec_in2<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
Copies self into a new Vec with an allocator.
§Examples
use allocator_api2::{SliceExt, alloc::System};
let s = [10, 40, 30];
let x = s.to_vec_in2(System);
// Here, `s` and `x` can be modified independently.Sourcefn repeat2(&self, n: usize) -> Vec<T, Global>where
T: Copy,
fn repeat2(&self, n: usize) -> Vec<T, Global>where
T: Copy,
Creates a vector by copying a slice n times.
§Panics
This function will panic if the capacity would overflow.
§Examples
Basic usage:
use allocator_api2::{SliceExt, vec};
assert_eq!([1, 2].repeat2(3), vec![1, 2, 1, 2, 1, 2]);A panic upon overflow:
ⓘ
// this will panic at runtime
b"0123456789abcdef".repeat(usize::MAX);Provided Methods§
Sourcefn to_vec(&self) -> Vec<T, Global>where
T: Clone,
fn to_vec(&self) -> Vec<T, Global>where
T: Clone,
Copies self into a new Vec.
§Examples
use allocator_api2::SliceExt;
let s = [10, 40, 30];
let x = SliceExt::to_vec(&s[..]);
// Here, `s` and `x` can be modified independently.Sourcefn to_vec2(&self) -> Vec<T, Global>where
T: Clone,
fn to_vec2(&self) -> Vec<T, Global>where
T: Clone,
Copies self into a new Vec.
§Examples
use allocator_api2::SliceExt;
let s = [10, 40, 30];
let x = s.to_vec2();
// Here, `s` and `x` can be modified independently.Sourcefn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
fn to_vec_in<A: Allocator>(&self, alloc: A) -> Vec<T, A>where
T: Clone,
Copies self into a new Vec with an allocator.
§Examples
use allocator_api2::{SliceExt, alloc::System};
let s = [10, 40, 30];
let x = SliceExt::to_vec_in(&s[..], System);
// Here, `s` and `x` can be modified independently.Sourcefn repeat(&self, n: usize) -> Vec<T, Global>where
T: Copy,
fn repeat(&self, n: usize) -> Vec<T, Global>where
T: Copy,
Creates a vector by copying a slice n times.
§Panics
This function will panic if the capacity would overflow.
§Examples
Basic usage:
use allocator_api2::{SliceExt, vec};
assert_eq!(SliceExt::repeat(&[1, 2][..], 3), vec![1, 2, 1, 2, 1, 2]);A panic upon overflow:
ⓘ
// this will panic at runtime
b"0123456789abcdef".repeat(usize::MAX);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.