mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-12-01 00:30:23 -05:00
version: 0.0.3
feat: list UPS variables docs: improve docs and enforce
This commit is contained in:
parent
b36c855b2c
commit
0ba5e4565f
8 changed files with 66 additions and 13 deletions
11
src/error.rs
11
src/error.rs
|
|
@ -6,7 +6,11 @@ use std::io;
|
|||
pub enum NutError {
|
||||
/// Occurs when the username/password combination is rejected.
|
||||
AccessDenied,
|
||||
/// Occurs when the specified UPS device does not exist.
|
||||
UnknownUps,
|
||||
/// Occurs when the response type or content wasn't expected at the current stage.
|
||||
UnexpectedResponse,
|
||||
/// Occurs when the response type is not recognized by the client.
|
||||
UnknownResponseType(String),
|
||||
/// Generic (usually internal) client error.
|
||||
Generic(String),
|
||||
|
|
@ -16,7 +20,8 @@ impl fmt::Display for NutError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::AccessDenied => write!(f, "Authentication failed"),
|
||||
Self::UnexpectedResponse => write!(f, "Unexpected server response"),
|
||||
Self::UnknownUps => write!(f, "Unknown UPS device name"),
|
||||
Self::UnexpectedResponse => write!(f, "Unexpected server response content"),
|
||||
Self::UnknownResponseType(ty) => write!(f, "Unknown response type: {}", ty),
|
||||
Self::Generic(msg) => write!(f, "Internal client error: {}", msg),
|
||||
}
|
||||
|
|
@ -25,9 +30,12 @@ impl fmt::Display for NutError {
|
|||
|
||||
impl std::error::Error for NutError {}
|
||||
|
||||
/// Encapsulation for errors emitted by the client library.
|
||||
#[derive(Debug)]
|
||||
pub enum ClientError {
|
||||
/// Encapsulates IO errors.
|
||||
Io(io::Error),
|
||||
/// Encapsulates NUT and client-specific errors.
|
||||
Nut(NutError),
|
||||
}
|
||||
|
||||
|
|
@ -54,4 +62,5 @@ impl From<NutError> for ClientError {
|
|||
}
|
||||
}
|
||||
|
||||
/// Result type for [`ClientError`]
|
||||
pub type Result<T> = std::result::Result<T, ClientError>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue