pub enum Error {
Os(Error),
Truncated,
BufferTooSmall {
needed: usize,
},
Interrupted,
ConnectionClosed,
Overrun,
WouldBlock,
}Expand description
Errors that can occur during proc connector operations.
§Example: matching on errors
use proc_connector::Error;
fn handle_error(e: Error) -> String {
match &e {
Error::Os(e) => format!("os error: {e}"),
Error::Truncated => "truncated message".into(),
Error::BufferTooSmall { needed } => {
format!("need {needed} bytes")
}
Error::Interrupted => "interrupted, retry".into(),
Error::ConnectionClosed => "connection closed".into(),
Error::Overrun => "events dropped".into(),
Error::WouldBlock => "would block".into(),
}
}
assert_eq!(handle_error(Error::Truncated), "truncated message");
assert_eq!(
handle_error(Error::BufferTooSmall { needed: 4096 }),
"need 4096 bytes"
);§Example: using the From<std::io::Error> impl
use proc_connector::Error;
fn returns_error() -> Result<(), Error> {
// std::io::Error is automatically converted via From
let _file = std::fs::File::open("/nonexistent")?;
Ok(())
}
let err = returns_error().unwrap_err();
assert!(matches!(err, Error::Os(_)));Variants§
Os(Error)
System call failed (socket/bind/sendmsg/recvmsg).
Wraps std::io::Error for maximum compatibility.
Truncated
Received message is shorter than the minimum protocol header size.
BufferTooSmall
Provided receive buffer is too small.
Interrupted
Receive was interrupted by a signal; the operation should be retried.
ConnectionClosed
The netlink connection was closed (recv returned 0).
Overrun
Kernel reports message overrun; some events may have been dropped.
The caller should increase buffer size or consume events faster.
WouldBlock
Non-blocking recv found no data available (EAGAIN / EWOULDBLOCK).
Only returned when the socket is in non-blocking mode. Callers should wait for fd readiness (e.g. via poll/AsyncFd) and retry.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more