Skip to content

Commit c07e1d7

Browse files
committed
Introduce ErrorType trait to share errors for sync and async implementations
1 parent 2145d46 commit c07e1d7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

embedded-storage-async/src/nor_flash.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use core::future::Future;
2-
use embedded_storage::nor_flash::NorFlashError;
2+
use embedded_storage::nor_flash::ErrorType;
33

44
/// Read only NOR flash trait.
5-
pub trait AsyncReadNorFlash {
6-
/// Errors returned by this NOR flash.
7-
type Error: NorFlashError;
8-
5+
pub trait AsyncReadNorFlash: ErrorType {
96
/// The minumum number of bytes the storage peripheral can read
107
const READ_SIZE: usize;
118

src/nor_flash.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ impl NorFlashError for core::convert::Infallible {
1515
}
1616
}
1717

18+
/// A trait that NorFlash implementations can use to share an error type.
19+
pub trait ErrorType {
20+
/// Errors returned by this NOR flash.
21+
type Error: NorFlashError;
22+
}
23+
1824
/// NOR flash error kinds.
1925
///
2026
/// NOR flash implementations must map their error to those generic error kinds through the
@@ -49,10 +55,7 @@ impl core::fmt::Display for NorFlashErrorKind {
4955
}
5056

5157
/// Read only NOR flash trait.
52-
pub trait ReadNorFlash {
53-
/// Errors returned by this NOR flash.
54-
type Error: NorFlashError;
55-
58+
pub trait ReadNorFlash: ErrorType {
5659
/// The minumum number of bytes the storage peripheral can read
5760
const READ_SIZE: usize;
5861

0 commit comments

Comments
 (0)