|
68 | 68 | //! * `defmt-log`: By turning off the default features and enabling the
|
69 | 69 | //! `defmt-log` feature you can configure this crate to log messages over defmt
|
70 | 70 | //! instead.
|
| 71 | +//! * `core-error`: Enables implementations of `core::error::Error` for all error |
| 72 | +//! types. This raises the Minimum Supported Rust Version to 1.81. |
71 | 73 | //!
|
72 | 74 | //! You cannot enable both the `log` feature and the `defmt-log` feature.
|
73 | 75 |
|
@@ -272,6 +274,51 @@ where
|
272 | 274 | }
|
273 | 275 | }
|
274 | 276 |
|
| 277 | +impl<E> core::fmt::Display for Error<E> |
| 278 | +where |
| 279 | + E: core::fmt::Debug + core::fmt::Display, |
| 280 | +{ |
| 281 | + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 282 | + match self { |
| 283 | + Error::DeviceError(e) => write!(f, "error from underlying block device: {e}"), |
| 284 | + Error::FormatError(s) => write!(f, "filesystem is badly formatted: {s}"), |
| 285 | + Error::NoSuchVolume => write!(f, "no such volume"), |
| 286 | + Error::FilenameError(_) => write!(f, "bad filename"), |
| 287 | + Error::TooManyOpenVolumes => write!(f, "too many open volumes"), |
| 288 | + Error::TooManyOpenDirs => write!(f, "too many open directories"), |
| 289 | + Error::TooManyOpenFiles => write!(f, "too many open files"), |
| 290 | + Error::BadHandle => write!(f, "bad handle"), |
| 291 | + Error::NotFound => write!(f, "file or directory does not exist"), |
| 292 | + Error::FileAlreadyOpen => write!(f, "file already open"), |
| 293 | + Error::DirAlreadyOpen => write!(f, "directory already open"), |
| 294 | + Error::OpenedDirAsFile => write!(f, "cannot open directory as file"), |
| 295 | + Error::OpenedFileAsDir => write!(f, "cannot open file as directory"), |
| 296 | + Error::DeleteDirAsFile => write!(f, "cannot delete directory as file"), |
| 297 | + Error::VolumeStillInUse => write!(f, "volume is still in use"), |
| 298 | + Error::VolumeAlreadyOpen => write!(f, "cannot open volume twice"), |
| 299 | + Error::Unsupported => write!(f, "unsupported operation"), |
| 300 | + Error::EndOfFile => write!(f, "end of file"), |
| 301 | + Error::BadCluster => write!(f, "bad cluster"), |
| 302 | + Error::ConversionError => write!(f, "type conversion failed"), |
| 303 | + Error::NotEnoughSpace => write!(f, "not enough space on device"), |
| 304 | + Error::AllocationError => write!(f, "cluster not properly allocated"), |
| 305 | + Error::UnterminatedFatChain => write!(f, "FAT chain unterminated"), |
| 306 | + Error::ReadOnly => write!(f, "file is read-only"), |
| 307 | + Error::FileAlreadyExists => write!(f, "file already exists"), |
| 308 | + Error::BadBlockSize(size) => { |
| 309 | + write!(f, "bad block size: {size} (only 512 byte blocks supported)") |
| 310 | + } |
| 311 | + Error::InvalidOffset => write!(f, "invalid seek offset"), |
| 312 | + Error::DiskFull => write!(f, "disk full"), |
| 313 | + Error::DirAlreadyExists => write!(f, "directory already exists"), |
| 314 | + Error::LockError => write!(f, "already locked"), |
| 315 | + } |
| 316 | + } |
| 317 | +} |
| 318 | + |
| 319 | +#[cfg(feature = "core-error")] |
| 320 | +impl<E> core::error::Error for Error<E> where E: core::fmt::Debug + core::fmt::Display {} |
| 321 | + |
275 | 322 | /// A handle to a volume.
|
276 | 323 | ///
|
277 | 324 | /// A volume is a partition with a filesystem within it.
|
|
0 commit comments