Skip to content

Commit 91b86a4

Browse files
authored
Merge pull request #216 from rust-embedded-community/minor-doc-updates
Documentation updates
2 parents 7b13b7b + faf3e0d commit 91b86a4

File tree

7 files changed

+206
-58
lines changed

7 files changed

+206
-58
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
1212
- Raised the minimum supported Rust version to 1.87.0.
1313
- Removed `core-error` feature as MSRV is now above 1.81
1414
- Set edition to 2024
15+
- Removed `Error::DeleteDirAsFile` (breaking change)
16+
- Renamed `delete_file_in_dir` to `delete_entry_in_dir` because it can now delete empty directories (breaking change)
1517

1618
## [Version 0.9.0] - 2025-06-08
1719

examples/delete_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() -> Result<(), Error<std::io::Error>> {
3636
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
3737
let root_dir = volume.open_root_dir()?;
3838
println!("Deleting file {}...", FILE_TO_DELETE);
39-
root_dir.delete_file_in_dir(FILE_TO_DELETE)?;
39+
root_dir.delete_entry_in_dir(FILE_TO_DELETE)?;
4040
println!("Deleted!");
4141
Ok(())
4242
}

src/filesystem/directory.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ where
110110
/// Open a directory.
111111
///
112112
/// You can then read the directory entries with `iterate_dir` and `open_file_in_dir`.
113+
///
114+
/// See [`VolumeManager::open_dir`] for details, except the directory
115+
/// given is this directory.
113116
pub fn open_dir<N>(
114117
&self,
115118
name: N,
@@ -134,7 +137,10 @@ where
134137
Ok(())
135138
}
136139

137-
/// Look in a directory for a named file.
140+
/// Read the directory entry with the given filename from this directory, if it exists.
141+
///
142+
/// See [`VolumeManager::find_directory_entry`] for details, except the
143+
/// directory given is this directory.
138144
pub fn find_directory_entry<N>(&self, name: N) -> Result<DirEntry, Error<D::Error>>
139145
where
140146
N: ToShortFileName,
@@ -147,13 +153,8 @@ where
147153
///
148154
/// Long File Names will be ignored.
149155
///
150-
/// <div class="warning">
151-
///
152-
/// Do not attempt to call any methods on the VolumeManager or any of its
153-
/// handles from inside the callback. You will get a lock error because the
154-
/// object is already locked in order to do the iteration.
155-
///
156-
/// </div>
156+
/// See [`VolumeManager::iterate_dir`] for details, except the directory
157+
/// given is this directory.
157158
pub fn iterate_dir<F>(&self, func: F) -> Result<(), Error<D::Error>>
158159
where
159160
F: FnMut(&DirEntry),
@@ -164,18 +165,8 @@ where
164165
/// Call a callback function for each directory entry in a directory, and
165166
/// process Long File Names.
166167
///
167-
/// You must supply a [`LfnBuffer`] this API can use to temporarily hold the
168-
/// Long File Name. If you pass one that isn't large enough, any Long File
169-
/// Names that don't fit will be ignored and presented as if they only had a
170-
/// Short File Name.
171-
///
172-
/// <div class="warning">
173-
///
174-
/// Do not attempt to call any methods on the VolumeManager or any of its
175-
/// handles from inside the callback. You will get a lock error because the
176-
/// object is already locked in order to do the iteration.
177-
///
178-
/// </div>
168+
/// See [`VolumeManager::iterate_dir_lfn`] for details, except the
169+
/// directory given is this directory.
179170
pub fn iterate_dir_lfn<F>(
180171
&self,
181172
lfn_buffer: &mut LfnBuffer<'_>,
@@ -188,7 +179,10 @@ where
188179
.iterate_dir_lfn(self.raw_directory, lfn_buffer, func)
189180
}
190181

191-
/// Open a file with the given full path. A file can only be opened once.
182+
/// Open a file.
183+
///
184+
/// See [`VolumeManager::open_file_in_dir`] for details, except the
185+
/// directory given is this directory.
192186
pub fn open_file_in_dir<N>(
193187
&self,
194188
name: N,
@@ -203,15 +197,22 @@ where
203197
Ok(f.to_file(self.volume_mgr))
204198
}
205199

206-
/// Delete a closed file with the given filename, if it exists.
207-
pub fn delete_file_in_dir<N>(&self, name: N) -> Result<(), Error<D::Error>>
200+
/// Delete a file/directory.
201+
///
202+
/// See [`VolumeManager::delete_entry_in_dir`] for details, except the
203+
/// directory given is this directory.
204+
pub fn delete_entry_in_dir<N>(&self, name: N) -> Result<(), Error<D::Error>>
208205
where
209206
N: ToShortFileName,
210207
{
211-
self.volume_mgr.delete_file_in_dir(self.raw_directory, name)
208+
self.volume_mgr
209+
.delete_entry_in_dir(self.raw_directory, name)
212210
}
213211

214-
/// Make a directory inside this directory
212+
/// Create a new empty directory.
213+
///
214+
/// See [`VolumeManager::make_dir_in_dir`] for details, except the
215+
/// directory given is this directory.
215216
pub fn make_dir_in_dir<N>(&self, name: N) -> Result<(), Error<D::Error>>
216217
where
217218
N: ToShortFileName,

src/filesystem/files.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl RawFile {
4444
/// In contrast to a `RawFile`, a `File` holds a mutable reference to its
4545
/// parent `VolumeManager`, which restricts which operations you can perform.
4646
///
47-
/// If you drop a value of this type, it closes the file automatically, and but
47+
/// If you drop a value of this type, it closes the file automatically, but any
4848
/// error that may occur will be ignored. To handle potential errors, use
4949
/// the [`File::close`] method.
5050
pub struct File<'a, D, T, const MAX_DIRS: usize, const MAX_FILES: usize, const MAX_VOLUMES: usize>
@@ -76,46 +76,70 @@ where
7676
/// Read from the file
7777
///
7878
/// Returns how many bytes were read, or an error.
79+
///
80+
/// See [`VolumeManager::read`] for details, except the file given is this
81+
/// file.
7982
pub fn read(&self, buffer: &mut [u8]) -> Result<usize, crate::Error<D::Error>> {
8083
self.volume_mgr.read(self.raw_file, buffer)
8184
}
8285

8386
/// Write to the file
87+
///
88+
/// See [`VolumeManager::write`] for details, except the file given is this
89+
/// file.
8490
pub fn write(&self, buffer: &[u8]) -> Result<(), crate::Error<D::Error>> {
8591
self.volume_mgr.write(self.raw_file, buffer)
8692
}
8793

8894
/// Check if a file is at End Of File.
95+
///
96+
/// See [`VolumeManager::file_eof`] for details, except the file given is this
97+
/// file.
8998
pub fn is_eof(&self) -> bool {
9099
self.volume_mgr
91100
.file_eof(self.raw_file)
92101
.expect("Corrupt file ID")
93102
}
94103

95104
/// Seek a file with an offset from the current position.
105+
///
106+
/// See [`VolumeManager::file_seek_from_current`] for details, except the
107+
/// file given is this file.
96108
pub fn seek_from_current(&self, offset: i32) -> Result<(), crate::Error<D::Error>> {
97109
self.volume_mgr
98110
.file_seek_from_current(self.raw_file, offset)
99111
}
100112

101113
/// Seek a file with an offset from the start of the file.
114+
///
115+
/// See [`VolumeManager::file_seek_from_start`] for details, except the
116+
/// file given is this file.
102117
pub fn seek_from_start(&self, offset: u32) -> Result<(), crate::Error<D::Error>> {
103118
self.volume_mgr.file_seek_from_start(self.raw_file, offset)
104119
}
105120

106121
/// Seek a file with an offset back from the end of the file.
122+
///
123+
/// See [`VolumeManager::file_seek_from_end`] for details, except the file
124+
/// given is this file.
107125
pub fn seek_from_end(&self, offset: u32) -> Result<(), crate::Error<D::Error>> {
108126
self.volume_mgr.file_seek_from_end(self.raw_file, offset)
109127
}
110128

111129
/// Get the length of a file
130+
///
131+
/// See [`VolumeManager::file_length`] for details, except the file given
132+
/// is this file.
112133
pub fn length(&self) -> u32 {
113134
self.volume_mgr
114135
.file_length(self.raw_file)
115136
.expect("Corrupt file ID")
116137
}
117138

118139
/// Get the current offset of a file
140+
///
141+
/// See [`VolumeManager::file_offset`] for details, except the file given
142+
/// is this file.
119143
pub fn offset(&self) -> u32 {
120144
self.volume_mgr
121145
.file_offset(self.raw_file)
@@ -130,6 +154,9 @@ where
130154
}
131155

132156
/// Flush any written data by updating the directory entry.
157+
///
158+
/// See [`VolumeManager::flush_file`] for details, except the file given
159+
/// is this file.
133160
pub fn flush(&self) -> Result<(), Error<D::Error>> {
134161
self.volume_mgr.flush_file(self.raw_file)
135162
}

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ where
189189
OpenedDirAsFile,
190190
/// You can't open a file as a directory
191191
OpenedFileAsDir,
192-
/// You can't delete a directory as a file [no longer being emitted]
193-
DeleteDirAsFile,
194192
/// You can't delete a non-empty directory
195193
DeleteNonEmptyDir,
196194
/// You can't close a volume with open files or directories
@@ -254,7 +252,6 @@ impl<E: Debug> embedded_io::Error for Error<E> {
254252
Error::NotFound => ErrorKind::NotFound,
255253
Error::OpenedDirAsFile
256254
| Error::OpenedFileAsDir
257-
| Error::DeleteDirAsFile
258255
| Error::DeleteNonEmptyDir
259256
| Error::BadCluster
260257
| Error::ConversionError
@@ -294,7 +291,6 @@ where
294291
Error::DirAlreadyOpen => write!(f, "directory already open"),
295292
Error::OpenedDirAsFile => write!(f, "cannot open directory as file"),
296293
Error::OpenedFileAsDir => write!(f, "cannot open file as directory"),
297-
Error::DeleteDirAsFile => write!(f, "cannot delete directory as file"),
298294
Error::DeleteNonEmptyDir => write!(f, "cannot delete a non-empty directory"),
299295
Error::VolumeStillInUse => write!(f, "volume is still in use"),
300296
Error::VolumeAlreadyOpen => write!(f, "cannot open volume twice"),

0 commit comments

Comments
 (0)