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 13, 2024
1 parent 932a40f commit a1f8d9e
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 @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
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 a1f8d9e

Please sign in to comment.