From 287bb1ca31776f447b980bb7a13c97e6fadc12cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 20 Jun 2024 09:50:08 +0200 Subject: [PATCH] Remove default fature requirement and add an heapless-0.8 feature --- Cargo.toml | 3 ++- src/lib.rs | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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(); } }