Skip to content

Commit 6c3fa0a

Browse files
committed
Fix defmt logging.
1 parent 06af669 commit 6c3fa0a

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ chrono = "0.4"
2626

2727
[features]
2828
default = ["log"]
29-
defmt-log = ["defmt"]
29+
defmt-log = ["dep:defmt"]
30+
log = ["dep:log"]

src/filesystem/directory.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl RawDirectory {
7575
/// If you drop a value of this type, it closes the directory automatically. However,
7676
/// it holds a mutable reference to its parent `VolumeManager`, which restricts
7777
/// which operations you can perform.
78-
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
7978
pub struct Directory<
8079
'a,
8180
D,
@@ -194,6 +193,18 @@ where
194193
}
195194
}
196195

196+
#[cfg(feature = "defmt-log")]
197+
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
198+
defmt::Format for Directory<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
199+
where
200+
D: crate::BlockDevice,
201+
T: crate::TimeSource,
202+
{
203+
fn format(&self, fmt: defmt::Formatter) {
204+
defmt::write!(fmt, "Directory({})", self.raw_directory.0 .0)
205+
}
206+
}
207+
197208
/// Holds information about an open file on disk
198209
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
199210
#[derive(Debug, Clone)]

src/filesystem/files.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl RawFile {
4242
/// If you drop a value of this type, it closes the file automatically. However,
4343
/// it holds a mutable reference to its parent `VolumeManager`, which restricts
4444
/// which operations you can perform.
45-
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
4645
pub struct File<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
4746
where
4847
D: crate::BlockDevice,
@@ -150,6 +149,18 @@ where
150149
}
151150
}
152151

152+
#[cfg(feature = "defmt-log")]
153+
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
154+
defmt::Format for File<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
155+
where
156+
D: crate::BlockDevice,
157+
T: crate::TimeSource,
158+
{
159+
fn format(&self, fmt: defmt::Formatter) {
160+
defmt::write!(fmt, "File({})", self.raw_file.0 .0)
161+
}
162+
}
163+
153164
/// Errors related to file operations
154165
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
155166
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ impl RawVolume {
263263
/// If you drop a value of this type, it closes the volume automatically. However,
264264
/// it holds a mutable reference to its parent `VolumeManager`, which restricts
265265
/// which operations you can perform.
266-
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
267266
pub struct Volume<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
268267
where
269268
D: crate::BlockDevice,
@@ -333,6 +332,18 @@ where
333332
}
334333
}
335334

335+
#[cfg(feature = "defmt-log")]
336+
impl<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
337+
defmt::Format for Volume<'a, D, T, MAX_DIRS, MAX_FILES, MAX_VOLUMES>
338+
where
339+
D: crate::BlockDevice,
340+
T: crate::TimeSource,
341+
{
342+
fn format(&self, fmt: defmt::Formatter) {
343+
defmt::write!(fmt, "Volume({})", self.raw_volume.0 .0)
344+
}
345+
}
346+
336347
/// Internal information about a Volume
337348
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
338349
#[derive(Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)