-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from rmsyn/riscv/result
riscv: add fallible functions
- Loading branch information
Showing
17 changed files
with
795 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use core::fmt; | ||
|
||
/// Convenience alias for the [Result](core::result::Result) type for the library. | ||
pub type Result<T> = core::result::Result<T, Error>; | ||
|
||
/// Represents error variants for the library. | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum Error { | ||
/// Attempted out-of-bounds access. | ||
IndexOutOfBounds { | ||
index: usize, | ||
min: usize, | ||
max: usize, | ||
}, | ||
/// Invalid field value. | ||
InvalidFieldValue { | ||
field: &'static str, | ||
value: usize, | ||
bitmask: usize, | ||
}, | ||
/// Invalid value of a register field that does not match any known variants. | ||
InvalidFieldVariant { field: &'static str, value: usize }, | ||
/// Invalid value. | ||
InvalidValue { value: usize, bitmask: usize }, | ||
/// Invalid value that does not match any known variants. | ||
InvalidVariant(usize), | ||
/// Unimplemented function or type. | ||
Unimplemented, | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::IndexOutOfBounds { index, min, max } => write!( | ||
f, | ||
"out-of-bounds access, index: {index}, min: {min}, max: {max}" | ||
), | ||
Self::InvalidFieldValue { | ||
field, | ||
value, | ||
bitmask, | ||
} => write!( | ||
f, | ||
"invalid {field} field value: {value:#x}, valid bitmask: {bitmask:#x}", | ||
), | ||
Self::InvalidFieldVariant { field, value } => { | ||
write!(f, "invalid {field} field variant: {value:#x}") | ||
} | ||
Self::InvalidValue { value, bitmask } => { | ||
write!(f, "invalid value: {value:#x}, valid bitmask: {bitmask:#x}",) | ||
} | ||
Self::InvalidVariant(value) => { | ||
write!(f, "invalid variant: {value:#x}") | ||
} | ||
Self::Unimplemented => write!(f, "unimplemented"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.