From e9d3a1ca98f80e92cd20ee9b94707067810b9036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 27 Aug 2025 16:49:59 +0200 Subject: [PATCH] Update to heapless 0.9 --- Cargo.toml | 4 ++-- core/Cargo.toml | 4 ++++ core/src/object_safe.rs | 22 ++++++++++++++++++++++ src/fs.rs | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58632039..3c9490cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/trussed-dev/littlefs2" [package] name = "littlefs2" description = "Idiomatic Rust API for littlefs" -version = "0.6.1" +version = "0.7.0" authors = ["Nicolas Stalder ", "Brandon Edens ", "The Trussed developers"] readme = "README.md" categories = ["embedded", "filesystem", "no-std"] @@ -26,7 +26,7 @@ all-features = true bitflags = "2.9.0" delog = "0.1.0" generic-array = "0.14" -heapless = "0.7" +heapless = "0.9" littlefs2-core = { version = "0.1", path = "core" } littlefs2-sys = { version = "0.3.1", features = ["multiversion"] } diff --git a/core/Cargo.toml b/core/Cargo.toml index 54e9f10f..8375676e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -12,14 +12,18 @@ repository.workspace = true bitflags = "2.6.0" heapless-bytes03 = { package = "heapless-bytes", version = "0.3", optional = true } heapless-bytes04 = { package = "heapless-bytes", version = "0.4", optional = true } +heapless-bytes05 = { package = "heapless-bytes", version = "0.5", optional = true } heapless07 = { package = "heapless", version = "0.7", optional = true } heapless08 = { package = "heapless", version = "0.8", optional = true } +heapless09 = { package = "heapless", version = "0.9", optional = true } serde = { version = "1", default-features = false, features = ["derive"], optional = true } [features] heapless-bytes03 = ["dep:heapless-bytes03"] heapless-bytes04 = ["dep:heapless-bytes04"] +heapless-bytes05 = ["dep:heapless-bytes05"] heapless07 = ["dep:heapless07"] heapless08 = ["dep:heapless08"] +heapless09 = ["dep:heapless09"] serde = ["dep:serde"] debug-error = [] diff --git a/core/src/object_safe.rs b/core/src/object_safe.rs index d4138d15..a0d28177 100644 --- a/core/src/object_safe.rs +++ b/core/src/object_safe.rs @@ -42,6 +42,17 @@ impl Vec for heapless_bytes04::Bytes { } } +#[cfg(feature = "heapless-bytes05")] +impl Vec for heapless_bytes05::Bytes { + fn resize_to_capacity(&mut self) { + heapless_bytes05::Bytes::resize_to_capacity(self) + } + + fn truncate(&mut self, n: usize) { + heapless_bytes05::Bytes::truncate(self, n) + } +} + #[cfg(feature = "heapless07")] impl Vec for heapless07::Vec { fn resize_to_capacity(&mut self) { @@ -64,6 +75,17 @@ impl Vec for heapless08::Vec { } } +#[cfg(feature = "heapless09")] +impl Vec for heapless09::Vec { + fn resize_to_capacity(&mut self) { + self.resize_default(self.capacity()).unwrap(); + } + + fn truncate(&mut self, n: usize) { + heapless09::Vec::truncate(self, n) + } +} + /// Object-safe trait for files. /// /// The methods for opening files cannot be implemented in this trait. Use these methods instead: diff --git a/src/fs.rs b/src/fs.rs index 529cd037..2c4af7a3 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -744,7 +744,7 @@ impl<'a, 'b, Storage: driver::Storage> File<'a, 'b, Storage> { } // This belongs in `io::Read` but really don't want that to have a generic parameter - pub fn read_to_end(&self, buf: &mut heapless::Vec) -> Result { + pub fn read_to_end(&self, buf: &mut heapless::VecView) -> Result { // My understanding of // https://github.com/littlefs-project/littlefs/blob/4c9146ea539f72749d6cc3ea076372a81b12cb11/lfs.c#L2816 // is that littlefs keeps reading until either the buffer is full, or the file is exhausted