From a1f8d9e87bc70765b488625e5844dbce4c1568cc 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 9deccc3d..10d06da5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,8 @@ jobs: - name: Check run: | cargo check --package littlefs2-core + 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 25ab8496..0f974f58 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -10,11 +10,15 @@ 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] +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 f5397f11..d4138d15 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) {