diff --git a/Cargo.toml b/Cargo.toml index 3ffc6f8..e4e517d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,5 @@ serde = { version = "1.0", default-features = false } serde_test = "1.0.176" [features] -default = [] +# From/Into implementation to `heapless::Vec` +"heapless-0.8" = [] diff --git a/src/lib.rs b/src/lib.rs index c796d71..30201c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,6 @@ #![cfg_attr(not(test), no_std)] #![allow(clippy::result_unit_err)] -#[cfg(not(feature = "default"))] -compile_error!("default features are required so that functionality can be put behind a feature flag in the future"); - use core::{ cmp::Ordering, fmt::{self, Debug}, @@ -32,12 +29,14 @@ pub type Bytes16 = Bytes<16>; pub type Bytes32 = Bytes<32>; pub type Bytes64 = Bytes<64>; +#[cfg(feature = "heapless-0.8")] impl From> for Bytes { fn from(vec: Vec) -> Self { Bytes { bytes: vec }.increase_capacity() } } +#[cfg(feature = "heapless-0.8")] impl From> for Vec { fn from(value: Bytes) -> Self { value.increase_capacity().bytes @@ -600,7 +599,9 @@ mod tests { fn from() { let _: Bytes<10> = [0; 10].into(); let _: Bytes<10> = (&[0; 8]).into(); + #[cfg(feature = "heapless-0.8")] let _: Bytes<10> = Vec::::new().into(); + #[cfg(feature = "heapless-0.8")] let _: Bytes<10> = Vec::::new().into(); } }