pub struct Error {
repr: Repr,
}core_io #154046)Expand description
Fields§
§repr: Reprcore_io #154046)Implementations§
Source§impl Error
Common errors constants for use in std
impl Error
Common errors constants for use in std
#[doc(hidden)]pub const INVALID_UTF8: Self
core_io_internals)#[doc(hidden)]pub const READ_EXACT_EOF: Self
core_io_internals)#[doc(hidden)]pub const UNKNOWN_THREAD_COUNT: Self
core_io_internals)#[doc(hidden)]pub const UNSUPPORTED_PLATFORM: Self
core_io_internals)#[doc(hidden)]pub const WRITE_ALL_EOF: Self
core_io_internals)#[doc(hidden)]pub const ZERO_TIMEOUT: Self
core_io_internals)#[doc(hidden)]pub const NO_ADDRESSES: Self
core_io_internals)Source§impl Error
impl Error
Source#[doc(hidden)]pub unsafe fn from_custom_owner(custom: CustomOwner) -> Error
🔬This is a nightly-only experimental API. (core_io_internals)
#[doc(hidden)]pub unsafe fn from_custom_owner(custom: CustomOwner) -> Error
core_io_internals)§Safety
The provided CustomOwner must have been constructed from a Box from the alloc crate.
#[doc(hidden)]pub fn into_custom_owner(self) -> Result<CustomOwner, Self>
core_io_internals)Source#[doc(hidden)]pub const fn from_static_message(msg: &'static SimpleMessage) -> Error
🔬This is a nightly-only experimental API. (io_const_error_internals)
#[doc(hidden)]pub const fn from_static_message(msg: &'static SimpleMessage) -> Error
io_const_error_internals)Creates a new I/O error from a known kind of error as well as a constant message.
This function does not allocate.
You should not use this directly, and instead use the const_error!
macro: io::const_error!(ErrorKind::Something, "some_message").
This function should maybe change to from_static_message<const MSG: &'static str>(kind: ErrorKind) in the future, when const generics allow that.
Source#[doc(hidden)]pub unsafe fn from_raw_os_error_with_functions(
code: RawOsError,
functions: &'static OsFunctions,
) -> Error
🔬This is a nightly-only experimental API. (core_io_internals)
#[doc(hidden)]pub unsafe fn from_raw_os_error_with_functions(
code: RawOsError,
functions: &'static OsFunctions,
) -> Error
core_io_internals)§Safety
functions must point to data that is entirely constant; it must
not be created during runtime.
1.0.0 · Sourcepub fn raw_os_error(&self) -> Option<RawOsError>
pub fn raw_os_error(&self) -> Option<RawOsError>
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 + Send + Sync + 'static)>
pub fn get_ref(&self) -> Option<&(dyn Error + Send + Sync + '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 + Send + Sync + 'static)>
pub fn get_mut(&mut self) -> Option<&mut (dyn Error + Send + Sync + '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.0.0 · Sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
Returns the corresponding ErrorKind for this error.
This may be a value set by Rust code constructing custom io::Errors,
or if this io::Error was sourced from the operating system,
it will be a value inferred from the system’s error encoding.
See last_os_error for more details.
§Examples
use std::io::{Error, ErrorKind};
fn print_error(err: Error) {
println!("{:?}", err.kind());
}
fn main() {
// As no error has (visibly) occurred, this may print anything!
// It likely prints a placeholder for unidentified (non-)errors.
print_error(Error::last_os_error());
// Will print "AddrInUse".
print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
}#[doc(hidden)]pub fn is_interrupted(&self) -> bool
core_io_internals)Trait Implementations§
1.0.0 · Source§impl Error for Error
impl Error for Error
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
replaced by Error::source, which can support downcasting
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§#[doc(hidden)]fn type_id(&self, _: Internal) -> TypeIdwhere
Self: 'static,
#[doc(hidden)]fn type_id(&self, _: Internal) -> TypeIdwhere
Self: 'static,
error_type_id #60784)TypeId of self.1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
Blanket Implementations§
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<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more