From 1a82b7e81f481abafea53bc2fd776f5417cc1ade Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 12 Sep 2024 09:05:46 +0200 Subject: [PATCH] core: Add support for heapless-bytes Similar to the existing support for multiple heapless versions, this patch also adds support for heapless-bytes 0.3 and 0.4. --- .github/workflows/ci.yml | 2 ++ core/Cargo.toml | 4 ++++ core/src/object_safe.rs | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4eaab266..468c37d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: run: | cargo check --package littlefs2-core cargo check --package littlefs2-core --features dir-entry-path + cargo check --package littlefs2-core --features heapless-bytes03 + cargo check --package littlefs2-core --features heapless-bytes04 cargo check --package littlefs2-core --features heapless07 cargo check --package littlefs2-core --features heapless08 cargo check --package littlefs2-core --features serde diff --git a/core/Cargo.toml b/core/Cargo.toml index c0a1323e..1e6b7996 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -10,12 +10,16 @@ repository.workspace = true [dependencies] bitflags = "2.6.0" +heapless-bytes03 = { package = "heapless-bytes", version = "0.3", optional = true } +heapless-bytes04 = { package = "heapless-bytes", version = "0.4", optional = true } heapless07 = { package = "heapless", version = "0.7", optional = true } heapless08 = { package = "heapless", version = "0.8", optional = true } serde = { version = "1", default-features = false, features = ["derive"], optional = true } [features] dir-entry-path = [] +heapless-bytes03 = ["dep:heapless-bytes03"] +heapless-bytes04 = ["dep:heapless-bytes04"] heapless07 = ["dep:heapless07"] heapless08 = ["dep:heapless08"] serde = ["dep:serde"] diff --git a/core/src/object_safe.rs b/core/src/object_safe.rs index a8e06134..459a9c97 100644 --- a/core/src/object_safe.rs +++ b/core/src/object_safe.rs @@ -18,6 +18,30 @@ pub trait Vec: Default + AsRef<[u8]> + AsMut<[u8]> { fn truncate(&mut self, n: usize); } +#[cfg(feature = "heapless-bytes03")] +impl Vec for heapless_bytes03::Bytes { + fn resize_to_capacity(&mut self) { + heapless_bytes03::Bytes::resize_to_capacity(self) + } + + fn truncate(&mut self, n: usize) { + use core::ops::DerefMut as _; + + self.deref_mut().truncate(n) + } +} + +#[cfg(feature = "heapless-bytes04")] +impl Vec for heapless_bytes04::Bytes { + fn resize_to_capacity(&mut self) { + heapless_bytes04::Bytes::resize_to_capacity(self) + } + + fn truncate(&mut self, n: usize) { + heapless_bytes04::Bytes::truncate(self, n) + } +} + #[cfg(feature = "heapless07")] impl Vec for heapless07::Vec { fn resize_to_capacity(&mut self) {