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.
This commit is contained in:
Robin Krahl
2024-09-13 11:44:54 +02:00
parent 932a40f2da
commit a1f8d9e87b
3 changed files with 30 additions and 0 deletions
+2
View File
@@ -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
+4
View File
@@ -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
View File
@@ -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) {