pub struct FileIoError { /* private fields */ }Expand description
An error that occurs when reading or writing to a ReadableStorage or WritableStorage
This error is used to wrap errors that occur when reading or writing to a file. It contains the filename, offset, and context of the error.
Implementations§
Source§impl FileIoError
impl FileIoError
Sourcepub fn from_generic_no_file<T: Error>(error: T, context: &str) -> Self
pub fn from_generic_no_file<T: Error>(error: T, context: &str) -> Self
Create a new FileIoError from a generic error
Only use this constructor if you do not have any file or line information.
§Arguments
error- The error to wrap
Sourcepub const fn new(
inner: Error,
filename: Option<PathBuf>,
offset: u64,
context: Option<String>,
) -> Self
pub const fn new( inner: Error, filename: Option<PathBuf>, offset: u64, context: Option<String>, ) -> Self
Create a new FileIoError
§Arguments
inner- The inner errorfilename- The filename of the file that caused the erroroffset- The offset of the file that caused the errorcontext- The context of this error
Methods from Deref<Target = Error>§
1.0.0 · 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 + 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.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!"));
}Trait Implementations§
Source§impl Debug for FileIoError
impl Debug for FileIoError
Source§impl Deref for FileIoError
impl Deref for FileIoError
Source§impl Display for FileIoError
impl Display for FileIoError
Source§impl Error for FileIoError
impl Error for FileIoError
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
use the Display impl or to_string()