feat(transport): add constructors for non_exhaustive error types (#806)
AuthRequiredError, InsufficientScopeError, and DynamicTransportError were marked #[non_exhaustive] in #715/#768 but don't have constructors usable by external crates. Add new() for the error types and from_parts() for DynamicTransportError (the existing new() requires a Transport type parameter, making it unusable for test fixtures). Fixes #805
This commit is contained in:
parent
a743f15654
commit
ad3997268d
1 changed files with 51 additions and 9 deletions
|
|
@ -252,6 +252,24 @@ impl DynamicTransportError {
|
|||
error: Box::new(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a `DynamicTransportError` from raw parts.
|
||||
///
|
||||
/// Unlike [`new`](Self::new), this does not require a concrete [`Transport`] type,
|
||||
/// making it usable in test fixtures and other contexts where a real transport
|
||||
/// implementation is not available.
|
||||
pub fn from_parts(
|
||||
transport_name: impl Into<Cow<'static, str>>,
|
||||
transport_type_id: std::any::TypeId,
|
||||
error: Box<dyn std::error::Error + Send + Sync>,
|
||||
) -> Self {
|
||||
Self {
|
||||
transport_name: transport_name.into(),
|
||||
transport_type_id,
|
||||
error,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn downcast<T: Transport<R> + 'static, R: ServiceRole>(self) -> Result<T::Error, Self> {
|
||||
if !self.is::<T, R>() {
|
||||
Err(self)
|
||||
|
|
|
|||
Loading…
Reference in a new issue