From 7773ea171a3db2cd7edec71c203d522cf653ffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Mon, 9 Dec 2024 11:53:52 +0100 Subject: [PATCH 1/2] Add a const new associated function to ram_storage!'s output Useful to generate statics with the necessary ram --- CHANGELOG.md | 4 +++- src/macros.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1607700..eaa3c680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -- +### Added + +- Added a const `new` function for backends generated with the `ram_storage!` macro. ## [v0.7.2](https://github.com/trussed-dev/littlefs2/releases/tag/0.7.2) - 2026-06-10 diff --git a/src/macros.rs b/src/macros.rs index c6e448e7..d8a2f58e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -23,14 +23,20 @@ macro_rules! ram_storage { buf: [u8; $block_size * $block_count], } - impl Default for $Backend { - fn default() -> Self { - $Backend { + impl $Backend { + pub const fn new() -> Self { + Self { buf: [$erase_value; $block_size * $block_count], } } } + impl Default for $Backend { + fn default() -> Self { + Self::new() + } + } + pub struct $Name<'backend> { backend: &'backend mut $Backend, } From eb76ed57a432e8d816e35534ec0c85e661d8a447 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 23 Jun 2026 11:23:38 +0200 Subject: [PATCH 2/2] macros: Remove unused arguments for storage macros The corresponding types were removed from the Storage trait in 2c0dcdc29fc99341c4777d067a96e633b3719972 but the macros were never updated. --- CHANGELOG.md | 4 ++++ src/macros.rs | 12 ------------ src/tests.rs | 6 ------ tests/ui/constructors-fail.rs | 4 ---- tests/ui/sync-fail.rs | 4 ---- 5 files changed, 4 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa3c680..2340aebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added a const `new` function for backends generated with the `ram_storage!` macro. +### Removed + +- Removed unused arguments `filename_max_plus_one_ty` and `path_max_plus_one_ty` from `ram_storage!` and `const_ram_storage!` macros. + ## [v0.7.2](https://github.com/trussed-dev/littlefs2/releases/tag/0.7.2) - 2026-06-10 ### Fixed diff --git a/src/macros.rs b/src/macros.rs index d8a2f58e..e2fa0052 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -15,8 +15,6 @@ macro_rules! ram_storage { block_size=$block_size:expr, block_count=$block_count:expr, lookahead_size_ty=$lookahead_size:path, - filename_max_plus_one_ty=$filename_max_plus_one:path, - path_max_plus_one_ty=$path_max_plus_one:path, ) => { pub struct $Backend { @@ -98,8 +96,6 @@ macro_rules! ram_storage { block_size = 128, block_count = $bytes / 128, lookahead_size_ty = $crate::consts::U1, - filename_max_plus_one_ty = $crate::consts::U256, - path_max_plus_one_ty = $crate::consts::U256, ); }; (tiny) => { @@ -113,8 +109,6 @@ macro_rules! ram_storage { block_size = 128, block_count = 8, lookahead_size_ty = $crate::consts::U1, - filename_max_plus_one_ty = $crate::consts::U256, - path_max_plus_one_ty = $crate::consts::U256, ); }; (large) => { @@ -128,8 +122,6 @@ macro_rules! ram_storage { block_size = 256, block_count = 512, lookahead_size_ty = $crate::consts::U4, - filename_max_plus_one_ty = $crate::consts::U256, - path_max_plus_one_ty = $crate::consts::U256, ); }; } @@ -146,8 +138,6 @@ macro_rules! const_ram_storage { block_size=$block_size:expr, block_count=$block_count:expr, lookahead_size_ty=$lookahead_size:path, - filename_max_plus_one_ty=$filename_max_plus_one:path, - path_max_plus_one_ty=$path_max_plus_one:path, ) => { pub struct $Name { @@ -221,8 +211,6 @@ macro_rules! const_ram_storage { block_size = 512, block_count = $bytes / 512, lookahead_size_ty = $crate::consts::U1, - filename_max_plus_one_ty = $crate::consts::U256, - path_max_plus_one_ty = $crate::consts::U256, ); }; } diff --git a/src/tests.rs b/src/tests.rs index 33cc6dbd..c676ef83 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -17,8 +17,6 @@ ram_storage!( block_size = 256, block_count = 512, lookahead_size_ty = consts::U1, - filename_max_plus_one_ty = consts::U256, - path_max_plus_one_ty = consts::U256, ); ram_storage!( @@ -31,8 +29,6 @@ ram_storage!( block_size = 20 * 35, block_count = 32, lookahead_size_ty = consts::U16, - filename_max_plus_one_ty = consts::U256, - path_max_plus_one_ty = consts::U256, ); #[cfg(feature = "unstable-littlefs-patched")] @@ -46,8 +42,6 @@ ram_storage!( block_size = 20 * 35, block_count = 64, lookahead_size_ty = consts::U16, - filename_max_plus_one_ty = consts::U256, - path_max_plus_one_ty = consts::U256, ); #[test] diff --git a/tests/ui/constructors-fail.rs b/tests/ui/constructors-fail.rs index ebc701e1..8164cede 100644 --- a/tests/ui/constructors-fail.rs +++ b/tests/ui/constructors-fail.rs @@ -16,8 +16,6 @@ ram_storage!( block_size=256, block_count=512, lookaheadwords_size_ty=consts::U2, - filename_max_plus_one_ty=consts::U256, - path_max_plus_one_ty=consts::U256, result=Result, ); @@ -32,8 +30,6 @@ ram_storage!( block_size=20*35, block_count=32, lookaheadwords_size_ty=consts::U2, - filename_max_plus_one_ty=consts::U256, - path_max_plus_one_ty=consts::U256, result=Result, ); diff --git a/tests/ui/sync-fail.rs b/tests/ui/sync-fail.rs index 3954abf1..6f2bc78c 100644 --- a/tests/ui/sync-fail.rs +++ b/tests/ui/sync-fail.rs @@ -16,8 +16,6 @@ ram_storage!( block_size=256, block_count=512, lookaheadwords_size_ty=consts::U2, - filename_max_plus_one_ty=consts::U256, - path_max_plus_one_ty=consts::U256, result=Result, ); @@ -32,8 +30,6 @@ ram_storage!( block_size=20*35, block_count=32, lookaheadwords_size_ty=consts::U2, - filename_max_plus_one_ty=consts::U256, - path_max_plus_one_ty=consts::U256, result=Result, );