use std::{error::Error as StdError, result::Result as StdResult, sync::Arc};
use crate::runtime::{Downcast, Origin, Provider, RuntimeError, RuntimeResult, TypeHint, Upcast};
impl<'a, T, E> Downcast<'a> for StdResult<T, E>
where
T: Downcast<'a>,
E: Send + Sync + 'static,
{
#[inline(always)]
fn downcast(origin: Origin, provider: Provider<'a>) -> RuntimeResult<Self> {
let inner = <T as Downcast<'a>>::downcast(origin, provider)?;
Ok(Ok(inner))
}
#[inline(always)]
fn hint() -> TypeHint {
<T as Downcast<'a>>::hint()
}
}
impl<'a, T, E> Upcast<'a> for StdResult<T, E>
where
T: Upcast<'a>,
E: StdError + Send + Sync + 'static,
{
type Output = <T as Upcast<'a>>::Output;
#[inline(always)]
fn upcast(origin: Origin, this: Self) -> RuntimeResult<Self::Output> {
match this {
Ok(inner) => <T as Upcast<'a>>::upcast(origin, inner),
Err(error) => Err(RuntimeError::UpcastResult {
access_origin: origin,
cause: Arc::new(error),
}),
}
}
#[inline(always)]
fn hint() -> TypeHint {
<T as Upcast<'a>>::hint()
}
}
impl<'a, T, E> Upcast<'a> for &'a StdResult<T, E>
where
&'a T: Upcast<'a>,
E: StdError + Clone + Send + Sync + 'static,
{
type Output = <&'a T as Upcast<'a>>::Output;
#[inline(always)]
fn upcast(origin: Origin, this: Self) -> RuntimeResult<Self::Output> {
match this {
Ok(inner) => <&'a T as Upcast<'a>>::upcast(origin, inner),
Err(error) => Err(RuntimeError::UpcastResult {
access_origin: origin,
cause: Arc::new(error.clone()),
}),
}
}
#[inline(always)]
fn hint() -> TypeHint {
<&'a T as Upcast<'a>>::hint()
}
}
impl<'a, T, E> Upcast<'a> for &'a mut StdResult<T, E>
where
&'a mut T: Upcast<'a>,
E: StdError + Clone + Send + Sync + 'static,
{
type Output = <&'a mut T as Upcast<'a>>::Output;
#[inline(always)]
fn upcast(origin: Origin, this: Self) -> RuntimeResult<Self::Output> {
match this {
Ok(inner) => <&'a mut T as Upcast<'a>>::upcast(origin, inner),
Err(error) => Err(RuntimeError::UpcastResult {
access_origin: origin,
cause: Arc::new(error.clone()),
}),
}
}
#[inline(always)]
fn hint() -> TypeHint {
<&'a mut T as Upcast<'a>>::hint()
}
}