From d92870910b062618fdaccde04cd4477769328f3e Mon Sep 17 00:00:00 2001 From: Raj Vengalil Date: Sat, 6 Aug 2022 13:55:09 +0530 Subject: [PATCH] Fix clippy and doctest warnings/errors --- rups/src/cmd.rs | 4 ++-- rups/src/proto/mod.rs | 4 ++++ rups/src/var.rs | 10 ++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/rups/src/cmd.rs b/rups/src/cmd.rs index 0460d03..9684263 100644 --- a/rups/src/cmd.rs +++ b/rups/src/cmd.rs @@ -833,7 +833,7 @@ implement_simple_commands! { pub fn get_network_version() -> String { ( { Command::NetworkVersion }, - { |row: String| Ok(row) }, + { Ok }, ) } @@ -841,7 +841,7 @@ implement_simple_commands! { pub fn get_server_version() -> String { ( { Command::Version }, - { |row: String| Ok(row) }, + { Ok }, ) } } diff --git a/rups/src/proto/mod.rs b/rups/src/proto/mod.rs index a1d5c6e..89d6a58 100644 --- a/rups/src/proto/mod.rs +++ b/rups/src/proto/mod.rs @@ -213,6 +213,9 @@ macro_rules! impl_sentences { /// 2. the decoded sentence /// /// ``` +/// # #[macro_use] extern crate rups; +/// # fn main() { +/// # #[cfg(test)] /// test_encode_decode!( /// ["GET", "VAR", "nutdev", "test.var"] <=> /// Sentences::QueryVar { @@ -220,6 +223,7 @@ macro_rules! impl_sentences { /// var_name: "test.var".into(), /// } /// ); +/// # } /// ``` #[allow(unused_macros)] macro_rules! test_encode_decode { diff --git a/rups/src/var.rs b/rups/src/var.rs index 84e0a24..cdfea10 100644 --- a/rups/src/var.rs +++ b/rups/src/var.rs @@ -5,7 +5,7 @@ use std::time::Duration; /// Well-known variable keys for NUT UPS devices. /// -/// List retrieved from: https://networkupstools.org/docs/user-manual.chunked/apcs01.html +/// List retrieved from: pub mod key { /// Device model. pub const DEVICE_MODEL: &str = "device.model"; @@ -31,7 +31,7 @@ pub mod key { /// Well-known variables for NUT UPS devices. /// -/// List retrieved from: https://networkupstools.org/docs/user-manual.chunked/apcs01.html +/// List retrieved from: #[derive(Debug, Clone, Eq, PartialEq)] pub enum Variable { /// Device model. @@ -196,10 +196,8 @@ impl TryFrom<&str> for VariableType { other => { if other.starts_with("STRING:") { let size = other - .splitn(2, ':') - .nth(1) - .map(|s| s.parse().ok()) - .flatten() + .split_once(':') + .and_then(|(_, s)| s.parse().ok()) .ok_or_else(|| crate::ClientError::generic("Invalid STRING definition"))?; Ok(Self::String(size)) } else {