abi_stable::std_types

Type Alias SendRBoxError

Source
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>

Source

pub fn from_fmt<T>(value: &T) -> Self
where T: Display + Debug + ?Sized,

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));
Source

pub fn from_debug<T>(value: &T) -> Self
where T: Debug + ?Sized,

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>

Source

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>

Source

pub fn type_id(&self) -> UTypeId

Returns the UTypeId of the error this wraps.

Source

pub fn heap_address(&self) -> usize

The address of the Box<_> this wraps

Source

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();
Source

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>

Source

pub fn new<T>(value: T) -> Self
where 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>

Source

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.

Source

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.

Source

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 than T.

§Example

Look at the type level documentation for the example.

Source

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 than T.

§Example

Look at the type level documentation for the example. the example.

Source

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 than T.

§Example

Look at the type level documentation for the example. the example.

Trait Implementations

Source§

impl<M> Debug for RBoxError_<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M> Display for RBoxError_<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M> Error for RBoxError_<M>

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Box<dyn Error + Send>> for RBoxError_<UnsyncSend>

Source§

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,

Source§

type StaticEquivalent = _static_RBoxError_<<M as GetStaticEquivalent_>::StaticEquivalent>

The 'static equivalent of Self
Source§

impl<M> StableAbi for RBoxError_<M>
where M: __StableAbi,

Source§

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
Source§

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more
Source§

const ABI_CONSTS: AbiConsts = _

const-equivalents of the associated types.