Struct twilio_async::io::Error 1.0.0[−][src]
pub struct Error { /* fields omitted */ }The error type for I/O operations of the Read, Write, Seek, and
associated traits.
Errors mostly originate from the underlying OS, but custom instances of
Error can be created with crafted error messages and a particular value of
ErrorKind.
Methods
impl Error[src]
impl Errorpub fn new<E>(kind: ErrorKind, error: E) -> Error where
E: Into<Box<Error + 'static + Sync + Send>>, [src]
pub fn new<E>(kind: ErrorKind, error: E) -> Error where
E: Into<Box<Error + 'static + Sync + Send>>, Creates a new I/O error from a known kind of error as well as an arbitrary error payload.
This function is used to generically create I/O errors which do not
originate from the OS itself. The error argument is an arbitrary
payload which will be contained in this Error.
Examples
use std::io::{Error, ErrorKind}; // errors can be created from strings let custom_error = Error::new(ErrorKind::Other, "oh no!"); // errors can also be created from other errors let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
pub fn last_os_error() -> Error[src]
pub fn last_os_error() -> ErrorReturns an error representing the last OS error which occurred.
This function reads the value of errno for the target platform (e.g.
GetLastError on Windows) and will return a corresponding instance of
Error for the error code.
Examples
use std::io::Error; println!("last OS error: {:?}", Error::last_os_error());
pub fn from_raw_os_error(code: i32) -> Error[src]
pub fn from_raw_os_error(code: i32) -> ErrorCreates a new instance of an Error from a particular OS error code.
Examples
On Linux:
use std::io; let error = io::Error::from_raw_os_error(22); assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
On Windows:
use std::io; let error = io::Error::from_raw_os_error(10022); assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
pub fn raw_os_error(&self) -> Option<i32>[src]
pub fn raw_os_error(&self) -> Option<i32>Returns the OS error that this error represents (if any).
If this Error was constructed via last_os_error or
from_raw_os_error, then this function will return Some, otherwise
it will return None.
Examples
use std::io::{Error, ErrorKind}; fn print_os_error(err: &Error) { if let Some(raw_os_err) = err.raw_os_error() { println!("raw OS error: {:?}", raw_os_err); } else { println!("Not an OS error"); } } fn main() { // Will print "raw OS error: ...". print_os_error(&Error::last_os_error()); // Will print "Not an OS error". print_os_error(&Error::new(ErrorKind::Other, "oh no!")); }
pub fn get_ref(&self) -> Option<&(Error + 'static + Sync + Send)>1.3.0[src]
pub fn get_ref(&self) -> Option<&(Error + 'static + Sync + Send)>Returns a reference to the inner error wrapped by this error (if any).
If this Error was constructed via new then this function will
return Some, otherwise it will return None.
Examples
use std::io::{Error, ErrorKind}; fn print_error(err: &Error) { if let Some(inner_err) = err.get_ref() { println!("Inner error: {:?}", inner_err); } else { println!("No inner error"); } } fn main() { // Will print "No inner error". print_error(&Error::last_os_error()); // Will print "Inner error: ...". print_error(&Error::new(ErrorKind::Other, "oh no!")); }
pub fn get_mut(&mut self) -> Option<&mut (Error + 'static + Sync + Send)>1.3.0[src]
pub fn get_mut(&mut self) -> Option<&mut (Error + 'static + Sync + Send)>Returns a mutable reference to the inner error wrapped by this error (if any).
If this Error was constructed via new then this function will
return Some, otherwise it will return None.
Examples
use std::io::{Error, ErrorKind}; use std::{error, fmt}; use std::fmt::Display; #[derive(Debug)] struct MyError { v: String, } impl MyError { fn new() -> MyError { MyError { v: "oh no!".to_string() } } fn change_message(&mut self, new_message: &str) { self.v = new_message.to_string(); } } impl error::Error for MyError { fn description(&self) -> &str { &self.v } } impl Display for MyError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "MyError: {}", &self.v) } } fn change_error(mut err: Error) -> Error { if let Some(inner_err) = err.get_mut() { inner_err.downcast_mut::<MyError>().unwrap().change_message("I've been changed!"); } err } fn print_error(err: &Error) { if let Some(inner_err) = err.get_ref() { println!("Inner error: {}", inner_err); } else { println!("No inner error"); } } fn main() { // Will print "No inner error". print_error(&change_error(Error::last_os_error())); // Will print "Inner error: ...". print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); }
pub fn into_inner(self) -> Option<Box<Error + 'static + Sync + Send>>1.3.0[src]
pub fn into_inner(self) -> Option<Box<Error + 'static + Sync + Send>>Consumes the Error, returning its inner error (if any).
If this Error was constructed via new then this function will
return Some, otherwise it will return None.
Examples
use std::io::{Error, ErrorKind}; fn print_error(err: Error) { if let Some(inner_err) = err.into_inner() { println!("Inner error: {}", inner_err); } else { println!("No inner error"); } } fn main() { // Will print "No inner error". print_error(Error::last_os_error()); // Will print "Inner error: ...". print_error(Error::new(ErrorKind::Other, "oh no!")); }
pub fn kind(&self) -> ErrorKind[src]
pub fn kind(&self) -> ErrorKindReturns the corresponding ErrorKind for this error.
Examples
use std::io::{Error, ErrorKind}; fn print_error(err: Error) { println!("{:?}", err.kind()); } fn main() { // Will print "No inner error". print_error(Error::last_os_error()); // Will print "Inner error: ...". print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); }
Trait Implementations
impl Error for Error[src]
impl Error for Errorfn description(&self) -> &str[src]
fn description(&self) -> &strThis method is soft-deprecated. Read more
fn cause(&self) -> Option<&Error>[src]
fn cause(&self) -> Option<&Error>The lower-level cause of this error, if any. Read more
impl Display for Error[src]
impl Display for Errorfn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>Formats the value using the given formatter. Read more
impl Debug for Error[src]
impl Debug for Errorfn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>Formats the value using the given formatter. Read more
impl From<ErrorKind> for Error1.14.0[src]
impl From<ErrorKind> for ErrorIntended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.
impl<W> From<IntoInnerError<W>> for Error[src]
impl<W> From<IntoInnerError<W>> for Errorfn from(iie: IntoInnerError<W>) -> Error[src]
fn from(iie: IntoInnerError<W>) -> ErrorPerforms the conversion.
impl From<NulError> for Error[src]
impl From<NulError> for Errorimpl From<Error> for Error[src]
impl From<Error> for Errorimpl From<Error> for Error[src]
impl From<Error> for Errorfn from(j: Error) -> Error[src]
fn from(j: Error) -> ErrorConvert a serde_json::Error into an io::Error.
JSON syntax and data errors are turned into InvalidData IO errors.
EOF errors are turned into UnexpectedEof IO errors.
use std::io; enum MyError { Io(io::Error), Json(serde_json::Error), } impl From<serde_json::Error> for MyError { fn from(err: serde_json::Error) -> MyError { use serde_json::error::Category; match err.classify() { Category::Io => { MyError::Io(err.into()) } Category::Syntax | Category::Data | Category::Eof => { MyError::Json(err) } } } }
impl From<Error> for EmitterError[src]
impl From<Error> for EmitterErrorfn from(err: Error) -> EmitterError[src]
fn from(err: Error) -> EmitterErrorPerforms the conversion.
impl From<Error> for Error[src]
impl From<Error> for Errorimpl From<Error> for TwilioErr[src]
impl From<Error> for TwilioErr