From 65a00c69ece2ec67a1ac89b1c3a4ff02de93caaa Mon Sep 17 00:00:00 2001 From: nm17 Date: Sat, 24 Feb 2024 19:53:47 +0400 Subject: [PATCH] style: clippy format --- src/ingest_protocol/error.rs | 4 ++-- src/ingest_protocol/packet_types.rs | 4 ++-- src/ingest_protocol/parser.rs | 12 +++++----- src/ingest_protocol/server.rs | 1 - src/main.rs | 22 +++++++++---------- src/web_server/app_error.rs | 18 +++++++-------- src/web_server/mod.rs | 8 +++---- src/web_server/old_app_api/config_app.rs | 9 ++++---- .../old_app_api/handlers/methods.rs | 14 ++++++------ src/web_server/old_app_api/handlers/mod.rs | 8 +++---- src/web_server/old_app_api/types/mod.rs | 4 ++-- src/web_server/old_devices_api/mod.rs | 18 +++++++-------- 12 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 src/ingest_protocol/server.rs diff --git a/src/ingest_protocol/error.rs b/src/ingest_protocol/error.rs index 80bb38a..b7e1d26 100644 --- a/src/ingest_protocol/error.rs +++ b/src/ingest_protocol/error.rs @@ -1,6 +1,6 @@ -use bstr::BStr; + use nom::error::VerboseError; -use std::fmt::{Debug, Display}; +use std::fmt::{Debug}; use std::num::ParseFloatError; use thiserror::Error as ThisError; diff --git a/src/ingest_protocol/packet_types.rs b/src/ingest_protocol/packet_types.rs index 0d71dcb..902964b 100644 --- a/src/ingest_protocol/packet_types.rs +++ b/src/ingest_protocol/packet_types.rs @@ -1,13 +1,13 @@ use crate::hashes::SupportedUnit; use crate::ingest_protocol::error::Error; use crate::ingest_protocol::parser::parse_mac_address; -use bstr::BStr; + use hifitime::Epoch; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use serde_with::formats::Separator; use serde_with::serde_as; -use std::borrow::Cow; + use std::collections::HashSet; use std::hash::{Hash, Hasher}; diff --git a/src/ingest_protocol/parser.rs b/src/ingest_protocol/parser.rs index c71e8d7..2b4fdfe 100644 --- a/src/ingest_protocol/parser.rs +++ b/src/ingest_protocol/parser.rs @@ -3,7 +3,7 @@ use nom::bytes::complete::tag; use nom::bytes::complete::take_until1; use nom::bytes::complete::{take, take_while, take_while1}; use nom::character::complete::hex_digit1; -use nom::{InputTake, Parser}; +use nom::{Parser}; use std::str::FromStr; use crate::ingest_protocol::error::Error; @@ -55,7 +55,7 @@ fn handle_special_sensor_macs<'a>( return Ok(false); } } - return Ok(true); + Ok(true) } pub fn parse_packet_body<'a>( @@ -69,7 +69,7 @@ pub fn parse_packet_body<'a>( match sensor_mac { "OWNER" => { - let (line, owner_value) = take_while1(|c| c != '\n')(line)?; + let (_line, owner_value) = take_while1(|c| c != '\n')(line)?; packet.owner = Some(owner_value.into()) @@ -82,11 +82,11 @@ pub fn parse_packet_body<'a>( tag("#"), take_while1(|c| c != '\n' && c != '#' && "1234567890.".contains(c)), ))(line)?; - let (line, sensor_name) = opt(preceded(tag("#"), take_while1(|c| c != '\n')))(line)?; + let (_line, sensor_name) = opt(preceded(tag("#"), take_while1(|c| c != '\n')))(line)?; let sensor_time = match sensor_time { Some(v) => Some(Epoch::from_unix_seconds( - v.parse().map_err(|e| TimestampParseError(e))?, + v.parse().map_err(TimestampParseError)?, )), None => None, }; @@ -103,7 +103,7 @@ pub fn parse_packet_body<'a>( } } - return Ok((line, ())); + Ok((line, ())) } pub fn parse_packet(input: &str) -> MyIError<&str, NMDeviceDataPacket> { diff --git a/src/ingest_protocol/server.rs b/src/ingest_protocol/server.rs deleted file mode 100644 index 3b37cdd..0000000 --- a/src/ingest_protocol/server.rs +++ /dev/null @@ -1 +0,0 @@ -async fn main() {} diff --git a/src/main.rs b/src/main.rs index c497e58..355943c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,20 +40,20 @@ mod hashes; mod ingest_protocol; mod web_server; -use std::borrow::Cow; -use std::collections::{BTreeSet, HashMap, HashSet}; -use std::mem::{size_of, size_of_val}; -use std::num::NonZeroUsize; -use std::str::FromStr; -use hifitime::Epoch; -use crate::ingest_protocol::error::Error; -use crate::ingest_protocol::error::Error::TimestampParseError; -use crate::ingest_protocol::{NMDeviceDataPacket, SensorValue}; -use crate::web_server::old_app_api::old_api_handler; + + + + + + + + + + use crate::web_server::server_main; -use rust_decimal::Decimal; + /*fn parse_sensor_value(input: Vec<&str>) -> MyIError, NarodMonValues> { Ok( diff --git a/src/web_server/app_error.rs b/src/web_server/app_error.rs index ee7b853..1ff7276 100644 --- a/src/web_server/app_error.rs +++ b/src/web_server/app_error.rs @@ -1,21 +1,21 @@ use derive_more::Display; use fred::prelude::*; -use ntex::http::header::{HeaderName, HeaderValue}; -use ntex::http::{HeaderMap, Response, StatusCode}; + +use ntex::http::{StatusCode}; use ntex::web; -use ntex::web::types::Json; -use ntex::web::{App, HttpRequest, HttpResponse}; -use std::borrow::Cow; -use std::fmt::format; -use std::str::FromStr; + +use ntex::web::{HttpRequest, HttpResponse}; + + + use thiserror::Error; -use crate::ingest_protocol::error::Error; + use crate::insert_header; use crate::web_server::old_devices_api::QSParserError; use rust_decimal::Decimal; use serde_json::json; -use ufmt::derive::uDebug; + #[derive(Debug, Error, Display)] pub enum AppError { diff --git a/src/web_server/mod.rs b/src/web_server/mod.rs index 6f6eaa3..e6a12d5 100644 --- a/src/web_server/mod.rs +++ b/src/web_server/mod.rs @@ -1,8 +1,8 @@ use crate::web_server::old_app_api::old_api_handler; use fred::bytes_utils::Str; use fred::prelude::*; -use std::time::Duration; -use tokio; + + pub(crate) mod app_error; pub mod old_app_api; @@ -15,7 +15,7 @@ pub struct NMAppState { } use crate::web_server::old_devices_api::device_handler; -use heapless::String as HeaplessString; + use ntex::web; pub async fn server_main() { @@ -26,7 +26,7 @@ pub async fn server_main() { // connect to the server, returning a handle to the task that drives the connection let _ = client.connect(); - let _ = client.wait_for_connect().await.unwrap(); + client.wait_for_connect().await.unwrap(); let asd: Str = client.ping().await.unwrap(); diff --git a/src/web_server/old_app_api/config_app.rs b/src/web_server/old_app_api/config_app.rs index 4e01abb..961c9b9 100644 --- a/src/web_server/old_app_api/config_app.rs +++ b/src/web_server/old_app_api/config_app.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use crate::web_server::app_error::AppError; use crate::web_server::old_app_api::handlers::{app_init, version}; @@ -9,7 +9,7 @@ use nom::AsBytes; use ntex::util::Bytes; use ntex::web; use ntex::web::types::State; -use serde_json::Value; + pub async fn old_api_handler( app_state: State, @@ -24,8 +24,9 @@ pub async fn old_api_handler( let mandatory_params: MandatoryParams<'_> = serde_json::from_slice(body_bytes)?; // TODO: Simd-JSON + // Ignore clippy singlematch match mandatory_params.cmd.as_ref() { - "version" => return Ok(version((), &app_state).await?), + "version" => return version((), &app_state).await, _ => {} } @@ -35,7 +36,7 @@ pub async fn old_api_handler( "appInit" => { let body: AppInitRequest = serde_json::from_slice(body_bytes)?; - return Ok(app_init(body, &app_state).await?); + app_init(body, &app_state).await } _ => Err(AppError::UnknownMethod(mandatory_params.cmd.to_string())), } diff --git a/src/web_server/old_app_api/handlers/methods.rs b/src/web_server/old_app_api/handlers/methods.rs index 7bf34a9..e1a9893 100644 --- a/src/web_server/old_app_api/handlers/methods.rs +++ b/src/web_server/old_app_api/handlers/methods.rs @@ -1,19 +1,19 @@ use crate::web_server::app_error::AppError; use crate::web_server::old_app_api::types::AppInitRequest; use crate::web_server::NMAppState; -use heapless::String as HeaplessString; -use serde_json::{json, Value as JsonValue}; -use ufmt::uwrite; + +use serde_json::{json}; + use crate::insert_header; use fred::interfaces::KeysInterface; use ntex::http::StatusCode; use ntex::web; -use ntex::web::types::State; -use ntex::web::Responder; + + pub async fn app_init( - body: AppInitRequest<'_>, + _body: AppInitRequest<'_>, app_state: &NMAppState, ) -> Result { let _: () = app_state @@ -24,7 +24,7 @@ pub async fn app_init( Ok(web::HttpResponse::build(StatusCode::OK).body("Hello world!")) } -pub async fn version(body: (), app_state: &NMAppState) -> Result { +pub async fn version(_body: (), _app_state: &NMAppState) -> Result { let mut resp = web::HttpResponse::build(StatusCode::OK).json(&json!({ "version": "indev", "iotishnik": true diff --git a/src/web_server/old_app_api/handlers/mod.rs b/src/web_server/old_app_api/handlers/mod.rs index f784445..9cb9400 100644 --- a/src/web_server/old_app_api/handlers/mod.rs +++ b/src/web_server/old_app_api/handlers/mod.rs @@ -1,7 +1,7 @@ mod methods; -use crate::hashes::SupportedUnit; + pub use methods::*; -use phf::phf_map; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; + + + diff --git a/src/web_server/old_app_api/types/mod.rs b/src/web_server/old_app_api/types/mod.rs index 774e05b..31d83e3 100644 --- a/src/web_server/old_app_api/types/mod.rs +++ b/src/web_server/old_app_api/types/mod.rs @@ -1,5 +1,5 @@ -use crate::hashes::SupportedUnit; -use serde::{Deserialize, Deserializer, Serialize}; + +use serde::{Deserialize, Serialize}; use std::borrow::Cow; // fn<'de, D>(D) -> Result where D: Deserializer<'de> diff --git a/src/web_server/old_devices_api/mod.rs b/src/web_server/old_devices_api/mod.rs index d03539d..e19be14 100644 --- a/src/web_server/old_devices_api/mod.rs +++ b/src/web_server/old_devices_api/mod.rs @@ -2,9 +2,9 @@ use crate::ingest_protocol::error::Error; use crate::ingest_protocol::parser::parse_mac_address; use crate::ingest_protocol::{NMDeviceDataPacket, NMJsonPacket}; use crate::web_server::app_error::AppError; -use bstr::BStr; -use ntex::http::error::DecodeError::Method; -use ntex::http::{HttpMessage, Payload, StatusCode}; + + +use ntex::http::{HttpMessage, StatusCode}; use ntex::util::{Bytes, HashMap}; use ntex::{http, web}; use std::sync::Arc; @@ -33,11 +33,11 @@ impl From for QSParserError { } } -pub async fn parse_nm_qs_format<'a>(input: &'a str) -> Result { +pub async fn parse_nm_qs_format(input: &str) -> Result { let parsed: HashMap<&str, &str> = serde_qs::from_str(input)?; - let (_, device_mac) = if let Some(id) = parsed.get("ID") { - parse_mac_address(*id)? + let (_, _device_mac) = if let Some(id) = parsed.get("ID") { + parse_mac_address(id)? } else { return Err(QSParserError::NoMAC); }; @@ -53,7 +53,7 @@ pub async fn parse_nm_qs_format<'a>(input: &'a str) -> Result( @@ -96,12 +96,12 @@ pub async fn device_handler<'a>( } } - if let Some(body) = real_body { + if let Some(_body) = real_body { // TODO } else { return Err(AppError::UnknownBody { json_err: json_error, - query_error: query_error, + query_error, }); }