Struct abi_stable::std_types::RIoError
source · #[repr(C)]pub struct RIoError { /* private fields */ }
Expand description
Ffi safe equivalent to std::io::Error
.
§Example
Defining an extern function to write a slice into a writer twice.
use abi_stable::{
erased_types::interfaces::IoWriteInterface,
rtry, sabi_extern_fn,
std_types::{RIoError, ROk, RResult},
traits::IntoReprC,
DynTrait, RMut,
};
use std::io::Write;
#[sabi_extern_fn]
pub fn write_slice_twice(
mut write: DynTrait<RMut<'_, ()>, IoWriteInterface>,
slice: &[u8],
) -> RResult<(), RIoError> {
rtry!(write.write_all(slice).into_c());
rtry!(write.write_all(slice).into_c());
ROk(())
}
Implementations§
source§impl RIoError
impl RIoError
sourcepub fn new<E>(kind: ErrorKind, error: E) -> Self
pub fn new<E>(kind: ErrorKind, error: E) -> Self
Constructs an RIoError
from an error and a std::io::ErrorKind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
let err = RIoError::new(ErrorKind::Other, "".parse::<u64>().unwrap_err());
sourcepub fn new_<E>(kind: ErrorKind, error: E) -> Self
pub fn new_<E>(kind: ErrorKind, error: E) -> Self
Constructs an RIoError
from a type convertible into a
Box<dyn std::error::Error + Send + Sync + 'static>
, and a std::io::ErrorKind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
let str_err = "Timeout receiving the response from server.";
let err = RIoError::new_(ErrorKind::TimedOut, str_err);
sourcepub fn from_kind(kind: ErrorKind) -> Self
pub fn from_kind(kind: ErrorKind) -> Self
Constructs an RIoError
from a std::io::ErrorKind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
let err = RIoError::from_kind(ErrorKind::AlreadyExists);
sourcepub fn with_box(
kind: ErrorKind,
error: Box<dyn ErrorTrait + Send + Sync + 'static>,
) -> Self
pub fn with_box( kind: ErrorKind, error: Box<dyn ErrorTrait + Send + Sync + 'static>, ) -> Self
Constructs an RIoError
from a
Box<dyn std::error::Error + Send + Sync + 'static>
and a std::io::ErrorKind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
let str_err = "Could not create file \"memes.txt\" because it already exists.";
let err = RIoError::with_box(ErrorKind::AlreadyExists, str_err.into());
sourcepub fn with_rboxerror(kind: ErrorKind, error: RBoxError) -> Self
pub fn with_rboxerror(kind: ErrorKind, error: RBoxError) -> Self
Constructs an RIoError
from an RBoxError
and a std::io::ErrorKind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
type DynErr = Box<dyn std::error::Error + Send + Sync>;
let str_err: DynErr = "IP address `256.256.256.256` is already in use.".into();
let err = RIoError::with_rboxerror(ErrorKind::AddrInUse, str_err.into());
sourcepub fn kind(&self) -> RIoErrorKind
pub fn kind(&self) -> RIoErrorKind
Retrieves the kind of io error.
§Example
use abi_stable::std_types::{RIoError, RIoErrorKind};
use std::io::ErrorKind;
let err = RIoError::from_kind(ErrorKind::AlreadyExists);
assert_eq!(err.kind(), RIoErrorKind::AlreadyExists);
sourcepub fn get_ref(&self) -> Option<&RBoxError>
pub fn get_ref(&self) -> Option<&RBoxError>
Gets the internal error,
returning None
if this was constructed with RIoError::from_kind
.
§Example
use abi_stable::std_types::{RBoxError, RIoError, RIoErrorKind};
use std::io::ErrorKind;
{
let err = RIoError::from_kind(ErrorKind::AlreadyExists);
assert_eq!(err.get_ref().map(|_| ()), None);
}
{
let msg = "Cannot access directory at \"/home/Steve/memes/\".";
let err = RIoError::new_(ErrorKind::PermissionDenied, msg);
assert!(err.get_ref().is_some());
}
sourcepub fn get_mut(&mut self) -> Option<&mut RBoxError>
pub fn get_mut(&mut self) -> Option<&mut RBoxError>
Gets the internal error,
returning None
if this was constructed with RIoError::from_kind
.
§Example
use abi_stable::std_types::{RBoxError, RIoError, RIoErrorKind};
use std::io::ErrorKind;
{
let mut err = RIoError::from_kind(ErrorKind::AlreadyExists);
assert_eq!(err.get_mut().map(|_| ()), None);
}
{
let mut msg = "Cannot access directory at \"/home/Patrick/373.15K takes/\".";
let mut err = RIoError::new_(ErrorKind::PermissionDenied, msg);
assert!(err.get_mut().is_some());
}
sourcepub fn into_inner(self) -> Option<RBoxError>
pub fn into_inner(self) -> Option<RBoxError>
Converts this into the internal error,
returning None
if this was constructed with RIoError::from_kind
.
§Example
use abi_stable::std_types::RIoError;
use std::io::ErrorKind;
{
let err = RIoError::from_kind(ErrorKind::AlreadyExists);
assert_eq!(err.into_inner().map(|_| ()), None);
}
{
let mut msg = "Cannot access directory at \"/home/wo_boat/blog/\".";
let err = RIoError::new_(ErrorKind::PermissionDenied, msg);
assert!(err.into_inner().is_some());
}
Trait Implementations§
source§impl Error for RIoError
impl Error for RIoError
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<RIoErrorKind> for RIoError
impl From<RIoErrorKind> for RIoError
source§fn from(kind: RIoErrorKind) -> Self
fn from(kind: RIoErrorKind) -> Self
source§impl GetStaticEquivalent_ for RIoError
impl GetStaticEquivalent_ for RIoError
source§type StaticEquivalent = _static_RIoError
type StaticEquivalent = _static_RIoError
'static
equivalent of Self
source§impl IntoReprRust for RIoError
impl IntoReprRust for RIoError
source§impl StableAbi for RIoError
impl StableAbi for RIoError
source§type IsNonZeroType = False
type IsNonZeroType = False
source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.Auto Trait Implementations§
impl Freeze for RIoError
impl RefUnwindSafe for RIoError
impl Send for RIoError
impl Sync for RIoError
impl Unpin for RIoError
impl UnwindSafe for RIoError
Blanket Implementations§
source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moresource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moresource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moresource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moresource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moresource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more