[][src]Struct abi_stable::std_types::std_io::RIoError

#[repr(C)]
pub struct RIoError { /* fields omitted */ }

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,
    std_types::{RIoError,RResult,ROk},
    traits::IntoReprC,
    DynTrait,
    sabi_extern_fn,
    rtry,
};

use std::io::Write;

#[sabi_extern_fn]
pub fn write_slice_twice(
    mut write:DynTrait<&mut (),IoWriteInterface>,
    slice:&[u8],
)->RResult<(),RIoError>{
    rtry!( write.write_all(slice).into_c() );
    rtry!( write.write_all(slice).into_c() );
    ROk(())
}


Methods

impl RIoError[src]

pub fn new<E>(kind: ErrorKind, error: E) -> Self where
    E: ErrorTrait + Send + Sync + 'static, 
[src]

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

pub fn new_<E>(kind: ErrorKind, error: E) -> Self where
    E: Into<Box<dyn ErrorTrait + Send + Sync + 'static>>, 
[src]

Constructs an RIoError from a type convertible into a Box<dyn ErrorTrait+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);

pub fn from_kind(kind: ErrorKind) -> Self[src]

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

pub fn with_box(
    kind: ErrorKind,
    error: Box<dyn ErrorTrait + Send + Sync + 'static>
) -> Self
[src]

Constructs an RIoError from a Box<dyn ErrorTrait+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());

pub fn with_rboxerror(kind: ErrorKind, error: RBoxError) -> Self[src]

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

pub fn kind(&self) -> RIoErrorKind[src]

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

pub fn get_ref(&self) -> Option<&RBoxError>[src]

Gets the internal error, returning None if this was constructed with RIoError::from_kind.

Example

use abi_stable::std_types::{RIoError,RIoErrorKind,RBoxError};
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());
}
 

pub fn get_mut(&mut self) -> Option<&mut RBoxError>[src]

Gets the internal error, returning None if this was constructed with RIoError::from_kind.

Example

use abi_stable::std_types::{RIoError,RIoErrorKind,RBoxError};
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());
}
 

pub fn into_inner(self) -> Option<RBoxError>[src]

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

impl IntoReprRust for RIoError[src]

type ReprRust = ioError

impl GetStaticEquivalent_ for RIoError[src]

type StaticEquivalent = _static_RIoError

impl SharedStableAbi for RIoError[src]

type IsNonZeroType = False

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

type Kind = __ValueKind

The kind of abi stability of this type,there are 2: Read more

impl Into<Error> for RIoError[src]

impl From<Error> for RIoError[src]

impl From<RIoErrorKind> for RIoError[src]

impl From<ErrorKind> for RIoError[src]

impl Display for RIoError[src]

impl Debug for RIoError[src]

impl Error for RIoError[src]

Auto Trait Implementations

Blanket Implementations

impl<This> StableAbi for This where
    This: SharedStableAbi<Kind = ValueKind>, 
[src]

impl<This> TransmuteElement for This where
    This: ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more

impl<T> SelfOps for T where
    T: ?Sized
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The error type returned when the conversion fails.