removed comments, finished optimizing formatted values

This commit is contained in:
D0RYU 2025-05-04 01:25:47 -04:00
parent 2b87888176
commit 5892f6def0
6 changed files with 24 additions and 67 deletions

20
Cargo.lock generated
View file

@ -463,9 +463,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.20"
version = "1.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a"
checksum = "8691782945451c1c383942c4874dbe63814f61cb57ef773cda2972682b7bb3c0"
dependencies = [
"jobserver",
"libc",
@ -762,9 +762,9 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
[[package]]
name = "dpi"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53"
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
[[package]]
name = "either"
@ -1342,7 +1342,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.9.0",
"libc",
"redox_syscall 0.5.11",
"redox_syscall 0.5.12",
]
[[package]]
@ -1989,7 +1989,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.11",
"redox_syscall 0.5.12",
"smallvec",
"windows-targets 0.52.6",
]
@ -2358,9 +2358,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.11"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3"
checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
dependencies = [
"bitflags 2.9.0",
]
@ -3988,9 +3988,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.7.8"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e27d6ad3dac991091e4d35de9ba2d2d00647c5d0fc26c5496dee55984ae111b"
checksum = "d9fb597c990f03753e08d3c29efbfcf2019a003b4bf4ba19225c158e1549f0f3"
dependencies = [
"memchr",
]

View file

@ -43,8 +43,8 @@ pub fn get_struct() -> Result<Vec<DeviceInfo>, DevicesError> {
Ok(sorted_devices
.into_iter()
.map(|(manufacturer, mut products)| {
products.sort(); // optional: sort product names
products.dedup(); // remove duplicates
products.sort();
products.dedup();
DeviceInfo {
manufacturer,
products,

View file

@ -1,9 +1,7 @@
use chrono::{DateTime, Local, TimeZone, Utc};
use derive_more::{Deref, From, with_trait::Display};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{Debug, Display, Formatter, Result as FMTResult},
ops::Deref,
};
use std::fmt;
#[derive(Debug, Serialize, Deserialize)]
pub struct DateTimeInfo {
@ -11,15 +9,15 @@ pub struct DateTimeInfo {
time: String,
}
#[derive(Clone)]
#[derive(Clone, Deref, From, PartialEq, Eq, PartialOrd, Ord)]
pub struct FmtDateTime<Tz: TimeZone>(pub DateTime<Tz>);
impl<Tz: TimeZone> Display for FmtDateTime<Tz>
where
Tz: TimeZone,
Tz::Offset: std::fmt::Display,
Tz::Offset: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> FMTResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:#?}",
@ -31,11 +29,11 @@ where
}
}
impl<Tz: TimeZone> Debug for FmtDateTime<Tz>
impl<Tz: TimeZone> fmt::Debug for FmtDateTime<Tz>
where
Tz::Offset: std::fmt::Display,
Tz::Offset: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> FMTResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(self, f)
}
}
@ -55,58 +53,20 @@ where
impl<'de, Tz> Deserialize<'de> for FmtDateTime<Tz>
where
Tz: TimeZone,
DateTime<Tz>: ToString + std::str::FromStr,
<DateTime<Tz> as std::str::FromStr>::Err: std::fmt::Display,
DateTime<Tz>: std::str::FromStr + Display,
<DateTime<Tz> as std::str::FromStr>::Err: Display,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
// 1. Pull a String out of the deserializer
let s = String::deserialize(deserializer)?;
// 2. Parse it, mapping any parse-error into a Serde error
<DateTime<Tz> as std::str::FromStr>::from_str(&s) // explicit, no ambiguity
s.parse::<DateTime<Tz>>()
.map(FmtDateTime)
.map_err(serde::de::Error::custom)
}
}
impl<Tz: TimeZone> Deref for FmtDateTime<Tz> {
type Target = DateTime<Tz>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<Tz: TimeZone> Eq for FmtDateTime<Tz> where DateTime<Tz>: Eq {}
impl<Tz: TimeZone> PartialEq for FmtDateTime<Tz>
where
DateTime<Tz>: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl<Tz: TimeZone> PartialOrd for FmtDateTime<Tz>
where
DateTime<Tz>: PartialOrd,
{
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<Tz: TimeZone> Ord for FmtDateTime<Tz>
where
DateTime<Tz>: Ord,
{
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.cmp(&other.0)
}
}
impl From<FmtDateTime<Utc>> for FmtDateTime<Local> {
fn from(dt: FmtDateTime<Utc>) -> Self {
FmtDateTime(dt.0.with_timezone(&Local))

View file

@ -30,10 +30,8 @@ impl<'de> Deserialize<'de> for FmtOffsetTime {
where
D: Deserializer<'de>,
{
// Deserialize the input as a string
let s = String::deserialize(deserializer)?;
// Attempt to parse the string into a DateTime<Local>
match DateTime::parse_from_rfc3339(&s) {
Ok(dt) => Ok(FmtOffsetTime(dt.with_timezone(&Local))),
Err(e) => Err(serde::de::Error::custom(format!(

View file

@ -12,7 +12,7 @@ where
Tz::Offset: Display,
Tz: TimeZone,
{
let formatted = date.format("%+").to_string(); // Format as RFC 3339
let formatted = date.format("%+").to_string();
serializer.serialize_str(&formatted)
}

View file

@ -316,7 +316,6 @@ fn format_entry_string(entry: &LogEntry, log_config: &LoggerConfig) -> String {
format!("{} {}", lvl, entry.message)
}
/// Formats the log entry as a json object ([`serde_json`]) and returns it as a [`String`]
fn format_entry_json(entry: &mut LogEntry, log_config: &LoggerConfig) -> String {
let mut json_object = serde_json::Map::new();