Struct holochain::prelude::dependencies::kitsune_p2p_types::dependencies::futures::io::Error
1.0.0 · source · pub struct Error { /* private fields */ }
Expand description
Implementations
sourceimpl Error
impl Error
sourcepub fn new<E>(kind: ErrorKind, error: E) -> Errorwhere
E: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub fn new<E>(kind: ErrorKind, error: E) -> Errorwhere
E: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
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
.
Note that this function allocates memory on the heap.
If no extra payload is required, use the From
conversion from
ErrorKind
.
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);
// creating an error without payload (and without memory allocation)
let eof_error = Error::from(ErrorKind::UnexpectedEof);
sourcepub fn other<E>(error: E) -> Errorwhere
E: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
🔬This is a nightly-only experimental API. (io_error_other
)
pub fn other<E>(error: E) -> Errorwhere
E: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
io_error_other
)Creates a new I/O error from an arbitrary error payload.
This function is used to generically create I/O errors which do not
originate from the OS itself. It is a shortcut for Error::new
with ErrorKind::Other
.
Examples
#![feature(io_error_other)]
use std::io::Error;
// errors can be created from strings
let custom_error = Error::other("oh no!");
// errors can also be created from other errors
let custom_error2 = Error::other(custom_error);
sourcepub fn last_os_error() -> Error
pub fn last_os_error() -> Error
Returns 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.
This should be called immediately after a call to a platform function, otherwise the state of the error value is indeterminate. In particular, other standard library functions may call platform functions that may (or may not) reset the error value even if they succeed.
Examples
use std::io::Error;
let os_error = Error::last_os_error();
println!("last OS error: {os_error:?}");
sourcepub fn from_raw_os_error(code: i32) -> Error
pub fn from_raw_os_error(code: i32) -> Error
Creates 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);
sourcepub fn raw_os_error(&self) -> Option<i32>
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!"));
}
1.3.0 · sourcepub fn get_ref(&self) -> Option<&(dyn Error + Sync + Send + 'static)>
pub fn get_ref(&self) -> Option<&(dyn Error + Sync + Send + 'static)>
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!"));
}
1.3.0 · sourcepub fn get_mut(&mut self) -> Option<&mut (dyn Error + Sync + Send + 'static)>
pub fn get_mut(&mut self) -> Option<&mut (dyn Error + Sync + Send + 'static)>
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 {}
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())));
}
1.3.0 · sourcepub fn into_inner(
self
) -> Option<Box<dyn Error + Sync + Send + 'static, Global>>
pub fn into_inner(
self
) -> Option<Box<dyn Error + Sync + Send + 'static, Global>>
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!"));
}
sourcepub fn downcast<E>(self) -> Result<Box<E, Global>, Error>where
E: 'static + Error + Send + Sync,
🔬This is a nightly-only experimental API. (io_error_downcast
)
pub fn downcast<E>(self) -> Result<Box<E, Global>, Error>where
E: 'static + Error + Send + Sync,
io_error_downcast
)Attempt to downgrade the inner error to E
if any.
If this Error
was constructed via new
then this function will
attempt to perform downgrade on it, otherwise it will return Err
.
If downgrade succeeds, it will return Ok
, otherwise it will also
return Err
.
Examples
#![feature(io_error_downcast)]
use std::fmt;
use std::io;
use std::error::Error;
#[derive(Debug)]
enum E {
Io(io::Error),
SomeOtherVariant,
}
impl fmt::Display for E {
// ...
}
impl Error for E {}
impl From<io::Error> for E {
fn from(err: io::Error) -> E {
err.downcast::<E>()
.map(|b| *b)
.unwrap_or_else(E::Io)
}
}
sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
Returns the corresponding ErrorKind
for this error.
Examples
use std::io::{Error, ErrorKind};
fn print_error(err: Error) {
println!("{:?}", err.kind());
}
fn main() {
// Will print "Uncategorized".
print_error(Error::last_os_error());
// Will print "AddrInUse".
print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
}
Trait Implementations
sourceimpl Error for Error
impl Error for Error
sourcefn description(&self) -> &str
fn description(&self) -> &str
sourcefn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
sourceimpl From<CompressError> for Error
impl From<CompressError> for Error
sourcefn from(data: CompressError) -> Error
fn from(data: CompressError) -> Error
sourceimpl From<DecompressError> for Error
impl From<DecompressError> for Error
sourcefn from(data: DecompressError) -> Error
fn from(data: DecompressError) -> Error
sourceimpl From<Error> for ConductorApiError
impl From<Error> for ConductorApiError
sourceimpl From<Error> for ConductorConfigError
impl From<Error> for ConductorConfigError
sourcefn from(source: Error) -> ConductorConfigError
fn from(source: Error) -> ConductorConfigError
sourceimpl From<Error> for ConductorError
impl From<Error> for ConductorError
sourceimpl From<Error> for DatabaseError
impl From<Error> for DatabaseError
sourcefn from(source: Error) -> DatabaseError
fn from(source: Error) -> DatabaseError
sourceimpl From<Error> for Error
impl From<Error> for Error
sourcefn from(j: Error) -> Error
fn from(j: Error) -> Error
Convert 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)
}
}
}
}
sourceimpl From<Error> for KitsuneP2pError
impl From<Error> for KitsuneP2pError
sourcefn from(source: Error) -> KitsuneP2pError
fn from(source: Error) -> KitsuneP2pError
sourceimpl From<Error> for ManagedTaskError
impl From<Error> for ManagedTaskError
sourceimpl From<Error> for MrBundleError
impl From<Error> for MrBundleError
sourcefn from(source: Error) -> MrBundleError
fn from(source: Error) -> MrBundleError
sourceimpl From<Error> for UnpackingError
impl From<Error> for UnpackingError
sourcefn from(source: Error) -> UnpackingError
fn from(source: Error) -> UnpackingError
sourceimpl From<Error> for WebsocketError
impl From<Error> for WebsocketError
sourcefn from(source: Error) -> WebsocketError
fn from(source: Error) -> WebsocketError
1.14.0 · sourceimpl From<ErrorKind> for Error
impl From<ErrorKind> for Error
Intended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.
sourceimpl From<ErrorStack> for Error
impl From<ErrorStack> for Error
sourcefn from(e: ErrorStack) -> Error
fn from(e: ErrorStack) -> Error
sourceimpl<W> From<IntoInnerError<W>> for Error
impl<W> From<IntoInnerError<W>> for Error
sourcefn from(iie: IntoInnerError<W>) -> Error
fn from(iie: IntoInnerError<W>) -> Error
sourceimpl From<PathPersistError> for Error
impl From<PathPersistError> for Error
sourcefn from(error: PathPersistError) -> Error
fn from(error: PathPersistError) -> Error
sourceimpl From<PersistError> for Error
impl From<PersistError> for Error
sourcefn from(error: PersistError) -> Error
fn from(error: PersistError) -> Error
impl From<ValueWriteError<Error>> for Error
impl From<ValueWriteError<Error>> for Error
fn from(err: ValueWriteError<Error>) -> Error
fn from(err: ValueWriteError<Error>) -> Error
impl NonBlockingError for Error
impl NonBlockingError for Error
fn into_non_blocking(self) -> Option<Error>
fn into_non_blocking(self) -> Option<Error>
impl RmpReadErr for Error
impl RmpWriteErr for Error
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations
impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
impl<T> FutureExt for T
impl<T> FutureExt for T
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
sourcefn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
sourcefn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.