aboutsummaryrefslogtreecommitdiff
path: root/src/libs/intertrait/cast/box.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-21 14:19:07 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 18:17:51 +0200
commit8c66b98bca6ed0a2990903fe8e0ea72def5c7be8 (patch)
treedeed78171051262dba7e8d97eba73a9aaf04dd5e /src/libs/intertrait/cast/box.rs
parentb3e1b993b028bbfa73638236cfbdb50ee478d3f0 (diff)
refactor!: change errors to be more sane
BREAKING CHANGE: Major improvements have been made to error types and the error_stack crate is no longer used
Diffstat (limited to 'src/libs/intertrait/cast/box.rs')
-rw-r--r--src/libs/intertrait/cast/box.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/libs/intertrait/cast/box.rs b/src/libs/intertrait/cast/box.rs
index 11f631a..31f06db 100644
--- a/src/libs/intertrait/cast/box.rs
+++ b/src/libs/intertrait/cast/box.rs
@@ -12,8 +12,6 @@
use std::any::type_name;
-use error_stack::report;
-
use crate::libs::intertrait::cast::error::CastError;
use crate::libs::intertrait::{caster, CastFrom};
@@ -22,7 +20,7 @@ pub trait CastBox
/// Casts a box to this trait into that of type `OtherTrait`.
fn cast<OtherTrait: ?Sized + 'static>(
self: Box<Self>,
- ) -> error_stack::Result<Box<OtherTrait>, CastError>;
+ ) -> Result<Box<OtherTrait>, CastError>;
}
/// A blanket implementation of `CastBox` for traits extending `CastFrom`.
@@ -30,15 +28,14 @@ impl<CastFromSelf: ?Sized + CastFrom> CastBox for CastFromSelf
{
fn cast<OtherTrait: ?Sized + 'static>(
self: Box<Self>,
- ) -> error_stack::Result<Box<OtherTrait>, CastError>
+ ) -> Result<Box<OtherTrait>, CastError>
{
match caster::<OtherTrait>((*self).type_id()) {
Some(caster) => Ok((caster.cast_box)(self.box_any())),
- None => Err(report!(CastError).attach_printable(format!(
- "From {} to {}",
- type_name::<CastFromSelf>(),
- type_name::<OtherTrait>()
- ))),
+ None => Err(CastError::CastFailed {
+ from: type_name::<CastFromSelf>(),
+ to: type_name::<OtherTrait>(),
+ }),
}
}
}