Skip to content

Commit

Permalink
core: Add support for heapless-bytes
Browse files Browse the repository at this point in the history
Similar to the existing support for multiple heapless versions, this
patch also adds support for heapless-bytes 0.3 and 0.4.
  • Loading branch information
robin-nitrokey committed Sep 12, 2024
1 parent e3ebbfc commit 1a82b7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
24 changes: 24 additions & 0 deletions core/src/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ pub trait Vec: Default + AsRef<[u8]> + AsMut<[u8]> {
fn truncate(&mut self, n: usize);
}

#[cfg(feature = "heapless-bytes03")]
impl<const N: usize> Vec for heapless_bytes03::Bytes<N> {
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<const N: usize> Vec for heapless_bytes04::Bytes<N> {
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<const N: usize> Vec for heapless07::Vec<u8, N> {
fn resize_to_capacity(&mut self) {
Expand Down

0 comments on commit 1a82b7e

Please sign in to comment.