pub enum NanonisError {
Io {
source: Error,
context: String,
},
Timeout(String),
Protocol(String),
Server {
code: i32,
message: String,
},
}Expand description
Variants§
Io
IO error with context describing what operation failed.
§Example
use nanonis_rs::NanonisError;
let io_err = std::io::Error::new(std::io::ErrorKind::ConnectionRefused, "refused");
let err = NanonisError::Io {
source: io_err,
context: "connecting to server".to_string(),
};
assert!(err.to_string().contains("connecting to server"));Timeout(String)
Connection or operation timeout.
Contains an optional description of what timed out.
§Example
use nanonis_rs::NanonisError;
let err = NanonisError::Timeout("waiting for scan to complete".to_string());
assert!(err.to_string().contains("scan"));Protocol(String)
Protocol error during parsing, validation, or type conversion.
This covers all errors related to the binary protocol:
- Unexpected response formats
- Type mismatches in received data
- Invalid command parameters
- Serialization failures
§Example
use nanonis_rs::NanonisError;
let err = NanonisError::Protocol("Expected f32, got i32".to_string());
assert!(err.to_string().contains("Expected f32"));Server
Error returned by the Nanonis server.
The server returns an error code and message when a command fails.
§Example
use nanonis_rs::NanonisError;
let err = NanonisError::Server {
code: -1,
message: "Invalid parameter".to_string(),
};
assert!(err.is_server_error());
assert_eq!(err.error_code(), Some(-1));Implementations§
Source§impl NanonisError
impl NanonisError
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if this is a server-side error.
Sourcepub fn error_code(&self) -> Option<i32>
pub fn error_code(&self) -> Option<i32>
Get error code if this is a server error.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Check if this is a timeout error.
Sourcepub fn is_protocol(&self) -> bool
pub fn is_protocol(&self) -> bool
Check if this is a protocol error.
Trait Implementations§
Source§impl Debug for NanonisError
impl Debug for NanonisError
Source§impl Display for NanonisError
impl Display for NanonisError
Source§impl Error for NanonisError
impl Error for NanonisError
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()
Source§impl From<Error> for NanonisError
impl From<Error> for NanonisError
Auto Trait Implementations§
impl Freeze for NanonisError
impl !RefUnwindSafe for NanonisError
impl Send for NanonisError
impl Sync for NanonisError
impl Unpin for NanonisError
impl !UnwindSafe for NanonisError
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