mirror of
https://github.com/trussed-dev/heapless-bytes.git
synced 2026-06-20 04:16:33 -07:00
Remove default fature requirement and add an heapless-0.8 feature
This commit is contained in:
+2
-1
@@ -19,4 +19,5 @@ serde = { version = "1.0", default-features = false }
|
||||
serde_test = "1.0.176"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# From/Into implementation to `heapless::Vec<u8, N>`
|
||||
"heapless-0.8" = []
|
||||
|
||||
+4
-3
@@ -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<const N: usize, const M: usize> From<Vec<u8, M>> for Bytes<N> {
|
||||
fn from(vec: Vec<u8, M>) -> Self {
|
||||
Bytes { bytes: vec }.increase_capacity()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "heapless-0.8")]
|
||||
impl<const N: usize, const M: usize> From<Bytes<M>> for Vec<u8, N> {
|
||||
fn from(value: Bytes<M>) -> 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::<u8, 10>::new().into();
|
||||
#[cfg(feature = "heapless-0.8")]
|
||||
let _: Bytes<10> = Vec::<u8, 9>::new().into();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user