ErrorExt: trap convenience method

This commit is contained in:
Pat Hickey
2021-01-25 12:14:27 -08:00
parent 634e911a4b
commit 957c434b67
2 changed files with 9 additions and 5 deletions

View File

@@ -48,6 +48,7 @@ pub enum ErrorKind {
}
pub trait ErrorExt {
fn trap(msg: impl Into<String>) -> Self;
fn too_big() -> Self;
fn badf() -> Self;
fn exist() -> Self;
@@ -64,6 +65,9 @@ pub trait ErrorExt {
}
impl ErrorExt for Error {
fn trap(msg: impl Into<String>) -> Self {
anyhow::anyhow!(msg.into())
}
fn too_big() -> Self {
ErrorKind::TooBig.into()
}