pub type SendRBoxError = RBoxError_<UnsyncSend>;
Expand description
Ffi safe equivalent to Box<dyn std::error::Error + Send>
.
Aliased Type§
struct SendRBoxError { /* private fields */ }
Implementations
Source§impl<M> RBoxError_<M>
impl<M> RBoxError_<M>
Sourcepub fn from_fmt<T>(value: &T) -> Self
pub fn from_fmt<T>(value: &T) -> Self
Constructs an RBoxError from an error, storing the Debug and Display messages without storing the error value.
§Example
use abi_stable::std_types::RBoxError;
let int_error = "".parse::<u32>().unwrap_err();
let display_fmt = int_error.to_string();
let debug_fmt = format!("{:#?}", int_error);
let err = RBoxError::from_fmt(&int_error);
assert_eq!(display_fmt, err.to_string());
assert_eq!(debug_fmt, format!("{:?}", err));
Sourcepub fn from_debug<T>(value: &T) -> Self
pub fn from_debug<T>(value: &T) -> Self
Constructs an RBoxError from a type that only implements Debug, storing the Debug message without storing the error value.
§Example
use abi_stable::std_types::RBoxError;
let int_error = "".parse::<u32>().unwrap_err();
let debug_fmt = format!("{:#?}", int_error);
let err = RBoxError::from_debug(&int_error);
assert_eq!(debug_fmt, format!("{}", err));
assert_eq!(debug_fmt, format!("{:#?}", err));
Source§impl<M> RBoxError_<M>
impl<M> RBoxError_<M>
Sourcepub fn to_formatted_error<N>(&self) -> RBoxError_<N>
pub fn to_formatted_error<N>(&self) -> RBoxError_<N>
Converts this error to a formatted error
This is used to decouple an RBoxError
from the dynamic library that produced it,
in order to unload the dynamic library.
Source§impl<M> RBoxError_<M>
impl<M> RBoxError_<M>
Sourcepub fn heap_address(&self) -> usize
pub fn heap_address(&self) -> usize
The address of the Box<_>
this wraps
Sourcepub fn as_unsync(&self) -> &UnsyncRBoxError
pub fn as_unsync(&self) -> &UnsyncRBoxError
Casts this &RBoxError_<_>
to &UnsyncRBoxError
.
§Example
use abi_stable::std_types::{RBoxError, UnsyncRBoxError};
use std::convert::TryFrom;
let int_err = u32::try_from(-1_i32).unwrap_err();
let err: RBoxError = RBoxError::new(int_err);
let unsync_err: &UnsyncRBoxError = err.as_unsync();
Sourcepub fn into_unsync(self) -> UnsyncRBoxError
pub fn into_unsync(self) -> UnsyncRBoxError
Converts this RBoxError_<_>
to UnsyncRBoxError
.
§Example
use abi_stable::std_types::{RBoxError, UnsyncRBoxError};
use std::convert::TryFrom;
let int_err = u64::try_from(-1338_i32).unwrap_err();
let err: RBoxError = RBoxError::new(int_err);
let unsync_err: UnsyncRBoxError = err.into_unsync();
Source§impl RBoxError_<UnsyncSend>
impl RBoxError_<UnsyncSend>
Sourcepub fn new<T>(value: T) -> Selfwhere
T: ErrorTrait + Send + 'static,
pub fn new<T>(value: T) -> Selfwhere
T: ErrorTrait + Send + 'static,
Constructs a Send + !Sync
RBoxError_
from an error.
§Example
use abi_stable::std_types::SendRBoxError;
let str_err = String::from_utf16(&[0xD834]).unwrap_err() ;
let err = SendRBoxError::new(str_err);
Source§impl RBoxError_<UnsyncSend>
impl RBoxError_<UnsyncSend>
Sourcepub fn from_box(this: Box<dyn ErrorTrait + Send + 'static>) -> Self
pub fn from_box(this: Box<dyn ErrorTrait + Send + 'static>) -> Self
Converts a Box<dyn Error + Send>
to a Send + !Sync
RBoxError_
.
RBoxError::from_box( RBoxError::into_box( err ) )
is a no-op with respect to the heap address of the RBoxError_<_>.
§Behavior
If the contents of the Box<_>
is an erased RBoxError_<_>
it will be returned directly,
otherwise the Box<_>
will be converted into an RBoxError_<_>
using RBoxError_::new
.
§Example
For an example of converting back and forth to a Box<dyn Error>
here is the example.
Sourcepub fn into_box(self) -> Box<dyn ErrorTrait + Send + 'static>
pub fn into_box(self) -> Box<dyn ErrorTrait + Send + 'static>
Converts an RBoxError_<_>
to a Box<dyn Error>
.
RBoxError::from_box( RBoxError::into_box( err ) )
is a no-op with respect to the heap address of the RBoxError_<_>.
§Behavior
If the contents of the RBoxError_<_>
is an erased Box<dyn Error + ... >
it will be returned directly,
otherwise the RBoxError_<_>
will be converted into an Box<dyn Error + ... >
using Box::new
.
§Example
For an example of converting back and forth to a Box<dyn Error>
here is the example.
Sourcepub fn downcast<T>(self) -> Result<RBox<T>, Self>where
T: ErrorTrait + 'static,
pub fn downcast<T>(self) -> Result<RBox<T>, Self>where
T: ErrorTrait + 'static,
Converts this RBoxError_<_>
to an RBox<T>
.
If was constructed from a Box<dyn Error + ... >
,
and this is being casted to another type,
it’ll first downcast to Box<dyn Error + ... >
,
then it’ll downcast the Box<dyn Error + ... >
into RBox<T>
.
§Errors
This returns Err(self)
in any of these cases:
-
The
RBoxError_
wasn’t constructed in the current dynamic library. -
The
RBoxError_
was constructed with a different type thanT
.
§Example
Look at the type level documentation for the example.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ErrorTrait + 'static,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: ErrorTrait + 'static,
Converts this &RBoxError_<_>
to a &T
.
If was constructed from a Box<dyn Error + ... >
,
and this is being casted to another type,
it’ll first downcast to &dyn Error + ...
,
then it’ll downcast the &dyn Error + ...
into &T
.
§Errors
This returns None
in any of these cases:
-
The
RBoxError_
wasn’t constructed in the current dynamic library. -
The
RBoxError_
was constructed with a different type thanT
.
§Example
Look at the type level documentation for the example. the example.
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: ErrorTrait + 'static,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: ErrorTrait + 'static,
Converts this &mut RBoxError_<_>
to a &mut T
.
If was constructed from a Box<dyn Error + ... >
,
and this is being casted to another type,
it’ll first downcast to &mut dyn Error + ...
,
then it’ll downcast the &mut dyn Error + ...
into &mut T
.
§Errors
This returns None
in any of these cases:
-
The
RBoxError_
wasn’t constructed in the current dynamic library. -
The
RBoxError_
was constructed with a different type thanT
.
§Example
Look at the type level documentation for the example. the example.
Trait Implementations
Source§impl<M> Debug for RBoxError_<M>
impl<M> Debug for RBoxError_<M>
Source§impl<M> Display for RBoxError_<M>
impl<M> Display for RBoxError_<M>
Source§impl<M> Error for RBoxError_<M>
impl<M> Error for RBoxError_<M>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Box<dyn Error + Send>> for RBoxError_<UnsyncSend>
impl From<Box<dyn Error + Send>> for RBoxError_<UnsyncSend>
Source§fn from(this: Box<dyn ErrorTrait + Send + 'static>) -> RBoxError_<UnsyncSend>
fn from(this: Box<dyn ErrorTrait + Send + 'static>) -> RBoxError_<UnsyncSend>
Converts a Box<dyn Error + Send>
to a Send + !Sync
RBoxError_
.
§Behavior
If the contents of the Box<_> is an erased RBoxError_<_>
it will be returned directly,
otherwise the Box<_>
will be converted into an RBoxError_<_>
using RBoxError_::new
.
Source§impl<M> GetStaticEquivalent_ for RBoxError_<M>where
M: __StableAbi,
impl<M> GetStaticEquivalent_ for RBoxError_<M>where
M: __StableAbi,
Source§type StaticEquivalent = _static_RBoxError_<<M as GetStaticEquivalent_>::StaticEquivalent>
type StaticEquivalent = _static_RBoxError_<<M as GetStaticEquivalent_>::StaticEquivalent>
'static
equivalent of Self
Source§impl<M> StableAbi for RBoxError_<M>where
M: __StableAbi,
impl<M> StableAbi for RBoxError_<M>where
M: __StableAbi,
Source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
Source§type IsNonZeroType = False
type IsNonZeroType = False
Source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.