@@ -48,6 +48,11 @@ pub struct Allocation<Storage: driver::Storage> {
48
48
49
49
// pub fn check_storage_requirements(
50
50
51
+ impl < Storage : driver:: Storage > Default for Allocation < Storage > {
52
+ fn default ( ) -> Self {
53
+ Self :: new ( )
54
+ }
55
+ }
51
56
impl < Storage : driver:: Storage > Allocation < Storage > {
52
57
53
58
pub fn new ( ) -> Allocation < Storage > {
@@ -86,21 +91,20 @@ impl<Storage: driver::Storage> Allocation<Storage> {
86
91
87
92
let cache = Cache :: new ( ) ;
88
93
89
- let filename_max_plus_one: u32 =
90
- <Storage as driver:: Storage >:: FILENAME_MAX_PLUS_ONE :: to_u32 ( ) ;
94
+ let filename_max_plus_one: u32 = crate :: consts:: FILENAME_MAX_PLUS_ONE ;
91
95
debug_assert ! ( filename_max_plus_one > 1 ) ;
92
96
debug_assert ! ( filename_max_plus_one <= 1_022 +1 ) ;
93
97
// limitation of ll-bindings
94
98
debug_assert ! ( filename_max_plus_one == 255 +1 ) ;
95
99
let path_max_plus_one: u32 = <Storage as driver:: Storage >:: PATH_MAX_PLUS_ONE :: to_u32 ( ) ;
96
100
// TODO: any upper limit?
97
101
debug_assert ! ( path_max_plus_one >= filename_max_plus_one) ;
98
- let file_max = Storage :: FILEBYTES_MAX as u32 ;
102
+ let file_max = crate :: consts :: FILEBYTES_MAX ;
99
103
assert ! ( file_max > 0 ) ;
100
104
assert ! ( file_max <= 2_147_483_647 ) ;
101
105
// limitation of ll-bindings
102
106
assert ! ( file_max == 2_147_483_647 ) ;
103
- let attr_max: u32 = < Storage as driver :: Storage > :: ATTRBYTES_MAX :: to_u32 ( ) ;
107
+ let attr_max: u32 = crate :: consts :: ATTRBYTES_MAX ;
104
108
assert ! ( attr_max > 0 ) ;
105
109
assert ! ( attr_max <= 1_022 ) ;
106
110
// limitation of ll-bindings
@@ -130,7 +134,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
130
134
131
135
name_max : filename_max_plus_one. wrapping_sub ( 1 ) ,
132
136
file_max,
133
- attr_max : attr_max ,
137
+ attr_max,
134
138
} ;
135
139
136
140
Self {
@@ -237,10 +241,7 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
237
241
// TODO: check if this is equivalent to `is_formatted`.
238
242
pub fn is_mountable ( storage : & mut Storage ) -> bool {
239
243
let alloc = & mut Allocation :: new ( ) ;
240
- match Filesystem :: mount ( alloc, storage) {
241
- Ok ( _) => true ,
242
- _ => false ,
243
- }
244
+ matches ! ( Filesystem :: mount( alloc, storage) , Ok ( _) )
244
245
}
245
246
246
247
// Can BorrowMut be implemented "unsafely" instead?
@@ -434,10 +435,10 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
434
435
path : & Path ,
435
436
id : u8 ,
436
437
) ->
437
- Result < Option < Attribute < Storage > > >
438
+ Result < Option < Attribute > >
438
439
{
439
440
let mut attribute = Attribute :: new ( id) ;
440
- let attr_max = < Storage as driver :: Storage > :: ATTRBYTES_MAX :: to_u32 ( ) ;
441
+ let attr_max = crate :: consts :: ATTRBYTES_MAX ;
441
442
442
443
let return_code = unsafe { ll:: lfs_getattr (
443
444
& mut self . alloc . borrow_mut ( ) . state ,
@@ -478,7 +479,7 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
478
479
pub fn set_attribute (
479
480
& self ,
480
481
path : & Path ,
481
- attribute : & Attribute < Storage >
482
+ attribute : & Attribute ,
482
483
) ->
483
484
Result < ( ) >
484
485
{
@@ -571,13 +572,13 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
571
572
/// Use [`Filesystem::attribute`](struct.Filesystem.html#method.attribute),
572
573
/// [`Filesystem::set_attribute`](struct.Filesystem.html#method.set_attribute), and
573
574
/// [`Filesystem::clear_attribute`](struct.Filesystem.html#method.clear_attribute).
574
- pub struct Attribute < S : driver :: Storage > {
575
+ pub struct Attribute {
575
576
id : u8 ,
576
- data : Bytes < S :: ATTRBYTES_MAX > ,
577
+ data : Bytes < crate :: consts :: ATTRBYTES_MAX_TYPE > ,
577
578
size : usize ,
578
579
}
579
580
580
- impl < S : driver :: Storage > Attribute < S > {
581
+ impl Attribute {
581
582
pub fn new ( id : u8 ) -> Self {
582
583
Attribute {
583
584
id,
@@ -591,13 +592,13 @@ impl<S: driver::Storage> Attribute<S> {
591
592
}
592
593
593
594
pub fn data ( & self ) -> & [ u8 ] {
594
- let attr_max = < S as driver :: Storage > :: ATTRBYTES_MAX :: to_usize ( ) ;
595
+ let attr_max = crate :: consts :: ATTRBYTES_MAX as _ ;
595
596
let len = cmp:: min ( attr_max, self . size ) ;
596
597
& self . data [ ..len]
597
598
}
598
599
599
600
pub fn set_data ( & mut self , data : & [ u8 ] ) -> & mut Self {
600
- let attr_max = < S as driver :: Storage > :: ATTRBYTES_MAX :: to_usize ( ) ;
601
+ let attr_max = crate :: consts :: ATTRBYTES_MAX as _ ;
601
602
let len = cmp:: min ( attr_max, data. len ( ) ) ;
602
603
self . data [ ..len] . copy_from_slice ( & data[ ..len] ) ;
603
604
self . size = len;
@@ -638,6 +639,12 @@ pub struct FileAllocation<S: driver::Storage>
638
639
config : ll:: lfs_file_config ,
639
640
}
640
641
642
+ impl < S : driver:: Storage > Default for FileAllocation < S > {
643
+ fn default ( ) -> Self {
644
+ Self :: new ( )
645
+ }
646
+ }
647
+
641
648
impl < S : driver:: Storage > FileAllocation < S > {
642
649
pub fn new ( ) -> Self {
643
650
let cache_size: u32 = <S as driver:: Storage >:: CACHE_SIZE :: to_u32 ( ) ;
@@ -782,7 +789,7 @@ impl<'a, 'b, Storage: driver::Storage> File<'a, 'b, Storage>
782
789
}
783
790
784
791
// This belongs in `io::Read` but really don't want that to have a generic parameter
785
- pub fn read_to_end < N : heapless :: ArrayLength < u8 > > ( & self , buf : & mut heapless:: Vec < u8 , N > ) -> Result < usize > {
792
+ pub fn read_to_end < const N : usize > ( & self , buf : & mut heapless:: Vec < u8 , N > ) -> Result < usize > {
786
793
// My understanding of
787
794
// https://github.com/ARMmbed/littlefs/blob/4c9146ea539f72749d6cc3ea076372a81b12cb11/lfs.c#L2816
788
795
// is that littlefs keeps reading until either the buffer is full, or the file is exhausted
@@ -1032,6 +1039,12 @@ pub struct ReadDirAllocation {
1032
1039
state : ll:: lfs_dir_t ,
1033
1040
}
1034
1041
1042
+ impl Default for ReadDirAllocation {
1043
+ fn default ( ) -> Self {
1044
+ Self :: new ( )
1045
+ }
1046
+ }
1047
+
1035
1048
impl ReadDirAllocation {
1036
1049
pub fn new ( ) -> Self {
1037
1050
unsafe { mem:: MaybeUninit :: zeroed ( ) . assume_init ( ) }
@@ -1258,7 +1271,7 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> {
1258
1271
}
1259
1272
1260
1273
/// Read the entire contents of a file into a bytes vector.
1261
- pub fn read < N : generic_array :: ArrayLength < u8 > > (
1274
+ pub fn read < const N : usize > (
1262
1275
& self ,
1263
1276
path : & Path ,
1264
1277
)
@@ -1375,7 +1388,7 @@ mod tests {
1375
1388
println ! ( "\n file {}: {:?}" , i, entry. file_name( ) ) ;
1376
1389
1377
1390
if entry. file_type ( ) . is_file ( ) {
1378
- let content: heapless:: Vec :: < u8 , heapless :: consts :: U256 > = fs. read ( entry. path ( ) ) ?;
1391
+ let content: heapless:: Vec :: < u8 , 256 > = fs. read ( entry. path ( ) ) ?;
1379
1392
println ! ( "content:\n {:?}" , core:: str :: from_utf8( & content) . unwrap( ) ) ;
1380
1393
// println!("and now the removal");
1381
1394
// fs.remove(entry.path())?;
@@ -1476,7 +1489,7 @@ mod tests {
1476
1489
}
1477
1490
) ?;
1478
1491
1479
- let content: heapless:: Vec < _ , consts :: U256 > = fs. read ( filename) ?;
1492
+ let content: heapless:: Vec < _ , 256 > = fs. read ( filename) ?;
1480
1493
assert_eq ! ( content, b"first part - second part" ) ;
1481
1494
// println!("content: {:?}", core::str::from_utf8(&content).unwrap());
1482
1495
Ok ( ( ) )
0 commit comments