diff --git a/Cargo.toml b/Cargo.toml index 8a9b5c6..71737e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,6 @@ version = "0.2.1" [dependencies.stable_deref_trait] default-features = false version = "1.1.1" + +[features] +alloc = [] diff --git a/src/lib.rs b/src/lib.rs index f0a3559..0f60e6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,3 +92,22 @@ impl AsMutSlice for [T; N] { self } } + +#[cfg(feature = "alloc")] +extern crate alloc; + +#[cfg(feature = "alloc")] +impl AsSlice for alloc::vec::Vec { + type Element = T; + + fn as_slice(&self) -> &[T] { + self + } +} + +#[cfg(feature = "alloc")] +impl AsMutSlice for alloc::vec::Vec { + fn as_mut_slice(&mut self) -> &mut [T] { + self + } +}