From 3b3535fec5713c7aaa71e1b10396f28671acd86c Mon Sep 17 00:00:00 2001 From: Eric Rodrigues Pires Date: Fri, 5 Dec 2025 21:14:14 -0300 Subject: [PATCH] Clippy + rustfmt --- duper-js-node/src/de.rs | 2 +- duper-js-node/src/ser.rs | 2 +- duper-python/src/de.rs | 4 +- duper/src/ast.rs | 4 +- duper/src/format.rs | 10 ++-- duper/src/parser/temporal.rs | 83 ++++++++++++++++++----------- duper/src/serde/ser.rs | 6 +-- duper/src/serde/temporal.rs | 1 - duper/src/visitor/pretty_printer.rs | 46 +++++++--------- duperq/src/types.rs | 4 +- 10 files changed, 88 insertions(+), 74 deletions(-) diff --git a/duper-js-node/src/de.rs b/duper-js-node/src/de.rs index 1055b3e..d68ed47 100644 --- a/duper-js-node/src/de.rs +++ b/duper-js-node/src/de.rs @@ -145,7 +145,7 @@ impl<'de, 'env> MapAccess<'de> for DuperMetaMapAccess<'env> { env: self.env, array: value.coerce_to_object().expect("checked object"), }) - } else if let Ok(bytes) = Uint8Array::from_unknown(value.clone()) { + } else if let Ok(bytes) = Uint8Array::from_unknown(value) { seed.deserialize(bytes.as_ref().into_deserializer()) } else { seed.deserialize(DuperMetaInnerObjectDeserializer { diff --git a/duper-js-node/src/ser.rs b/duper-js-node/src/ser.rs index 665a408..f8b4c92 100644 --- a/duper-js-node/src/ser.rs +++ b/duper-js-node/src/ser.rs @@ -14,7 +14,7 @@ pub enum SerdeError { #[error("{0}")] Custom(String), #[error("NAPI error: {0}")] - NAPI(#[from] napi::Error), + Napi(#[from] napi::Error), } impl serde_core::ser::Error for SerdeError { diff --git a/duper-python/src/de.rs b/duper-python/src/de.rs index cab4a61..fef7d13 100644 --- a/duper-python/src/de.rs +++ b/duper-python/src/de.rs @@ -104,7 +104,7 @@ impl<'py> DuperVisitor for Visitor<'py> { string: &'a str, ) -> Self::Value { Ok(VisitorValue { - value: PyString::new(self.py, &string).into_any(), + value: PyString::new(self.py, string).into_any(), duper: identifier .map(|identifier| Duper::from_identifier(identifier)?.into_pyobject(self.py)) .transpose()?, @@ -117,7 +117,7 @@ impl<'py> DuperVisitor for Visitor<'py> { bytes: &'a [u8], ) -> Self::Value { Ok(VisitorValue { - value: PyBytes::new(self.py, &bytes).into_any(), + value: PyBytes::new(self.py, bytes).into_any(), duper: identifier .map(|identifier| Duper::from_identifier(identifier)?.into_pyobject(self.py)) .transpose()?, diff --git a/duper/src/ast.rs b/duper/src/ast.rs index 9948778..006ec97 100644 --- a/duper/src/ast.rs +++ b/duper/src/ast.rs @@ -706,7 +706,7 @@ impl<'a> DuperValue<'a> { ) -> Result> { Ok(Self::Temporal(DuperTemporal::Unspecified { identifier: identifier - .map(|identifier| DuperTemporalIdentifier::try_from(identifier)) + .map(DuperTemporalIdentifier::try_from) .transpose()?, inner: DuperTemporalUnspecified::try_from(value)?, })) @@ -1031,7 +1031,7 @@ impl<'a> DuperTemporal<'a> { ) -> Result> { Ok(Self::Unspecified { identifier: identifier - .map(|identifier| DuperTemporalIdentifier::try_from(identifier)) + .map(DuperTemporalIdentifier::try_from) .transpose()?, inner: DuperTemporalUnspecified::try_from(value)?, }) diff --git a/duper/src/format.rs b/duper/src/format.rs index bc5edd5..dd82dfa 100644 --- a/duper/src/format.rs +++ b/duper/src/format.rs @@ -17,27 +17,27 @@ pub fn format_key<'a>(key: &'a DuperKey<'a>) -> Cow<'a, str> { if c == '_' { was_underscore_or_hyphen = true; } else if !c.is_ascii_alphabetic() { - return Cow::Owned(format_duper_string(&key.0.as_ref())); + return Cow::Owned(format_duper_string(key.0.as_ref())); } } else if c == '_' || c == '-' { if was_underscore_or_hyphen { - return Cow::Owned(format_duper_string(&key.0.as_ref())); + return Cow::Owned(format_duper_string(key.0.as_ref())); } was_underscore_or_hyphen = true; } else if c.is_ascii_alphanumeric() { was_underscore_or_hyphen = false; } else { - return Cow::Owned(format_duper_string(&key.0.as_ref())); + return Cow::Owned(format_duper_string(key.0.as_ref())); } } if was_underscore_or_hyphen { - Cow::Owned(format_duper_string(&key.0.as_ref())) + Cow::Owned(format_duper_string(key.0.as_ref())) } else { Cow::Borrowed(key.0.as_ref()) } } -pub fn format_duper_string<'a>(string: &'a str) -> String { +pub fn format_duper_string(string: &str) -> String { if string.is_empty() { // Empty string return r#""""#.into(); diff --git a/duper/src/parser/temporal.rs b/duper/src/parser/temporal.rs index 3cd9c62..d0a775c 100644 --- a/duper/src/parser/temporal.rs +++ b/duper/src/parser/temporal.rs @@ -3,9 +3,12 @@ use std::borrow::Cow; use chumsky::prelude::*; use crate::{ - ast::{DuperTemporal, DuperTemporalDuration, DuperTemporalInstant, DuperTemporalPlainDate, - DuperTemporalPlainDateTime, DuperTemporalPlainMonthDay, DuperTemporalPlainTime, - DuperTemporalPlainYearMonth, DuperTemporalZonedDateTime, DuperValue, DuperTemporalUnspecified}, + ast::{ + DuperTemporal, DuperTemporalDuration, DuperTemporalInstant, DuperTemporalPlainDate, + DuperTemporalPlainDateTime, DuperTemporalPlainMonthDay, DuperTemporalPlainTime, + DuperTemporalPlainYearMonth, DuperTemporalUnspecified, DuperTemporalZonedDateTime, + DuperValue, + }, parser::{ascii_alphabetic, ascii_alphanumeric, whitespace_and_comments}, }; @@ -41,9 +44,11 @@ pub fn temporal_instant<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::Instant { - inner: DuperTemporalInstant(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::Instant { + inner: DuperTemporalInstant(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_zoned_date_time<'a>() @@ -61,9 +66,11 @@ pub fn temporal_zoned_date_time<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::ZonedDateTime { - inner: DuperTemporalZonedDateTime(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::ZonedDateTime { + inner: DuperTemporalZonedDateTime(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_plain_date<'a>() @@ -81,9 +88,11 @@ pub fn temporal_plain_date<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::PlainDate { - inner: DuperTemporalPlainDate(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::PlainDate { + inner: DuperTemporalPlainDate(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_plain_time<'a>() @@ -101,9 +110,11 @@ pub fn temporal_plain_time<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::PlainTime { - inner: DuperTemporalPlainTime(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::PlainTime { + inner: DuperTemporalPlainTime(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_plain_date_time<'a>() @@ -121,9 +132,11 @@ pub fn temporal_plain_date_time<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::PlainDateTime { - inner: DuperTemporalPlainDateTime(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::PlainDateTime { + inner: DuperTemporalPlainDateTime(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_plain_year_month<'a>() @@ -141,9 +154,11 @@ pub fn temporal_plain_year_month<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::PlainYearMonth { - inner: DuperTemporalPlainYearMonth(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::PlainYearMonth { + inner: DuperTemporalPlainYearMonth(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_plain_month_day<'a>() @@ -161,9 +176,11 @@ pub fn temporal_plain_month_day<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|instant| DuperValue::Temporal(DuperTemporal::PlainMonthDay { - inner: DuperTemporalPlainMonthDay(Cow::Borrowed(instant)), - })) + .map(|instant| { + DuperValue::Temporal(DuperTemporal::PlainMonthDay { + inner: DuperTemporalPlainMonthDay(Cow::Borrowed(instant)), + }) + }) } pub fn temporal_duration<'a>() @@ -181,9 +198,11 @@ pub fn temporal_duration<'a>() .padded_by(whitespace_and_comments()), ) .then_ignore(just(')')) - .map(|duration| DuperValue::Temporal(DuperTemporal::Duration { - inner: DuperTemporalDuration(Cow::Borrowed(duration)), - })) + .map(|duration| { + DuperValue::Temporal(DuperTemporal::Duration { + inner: DuperTemporalDuration(Cow::Borrowed(duration)), + }) + }) } pub fn temporal_unspecified<'a>() @@ -192,10 +211,12 @@ pub fn temporal_unspecified<'a>() .to_slice() .delimited_by(just('\''), just('\'')) .padded_by(whitespace_and_comments()) - .map(|unspecified| DuperValue::Temporal(DuperTemporal::Unspecified { - identifier: None, - inner: DuperTemporalUnspecified(Cow::Borrowed(unspecified)), - })) + .map(|unspecified| { + DuperValue::Temporal(DuperTemporal::Unspecified { + identifier: None, + inner: DuperTemporalUnspecified(Cow::Borrowed(unspecified)), + }) + }) } // Inner values diff --git a/duper/src/serde/ser.rs b/duper/src/serde/ser.rs index 82bc8d4..ad9a2d8 100644 --- a/duper/src/serde/ser.rs +++ b/duper/src/serde/ser.rs @@ -1,8 +1,8 @@ use std::{borrow::Cow, marker::PhantomData}; use crate::{ - DuperIdentifier, DuperKey, DuperObject, DuperValue, - PrettyPrinter as DuperPrettyPrinter, Serializer as DuperSerializer, + DuperIdentifier, DuperKey, DuperObject, DuperValue, PrettyPrinter as DuperPrettyPrinter, + Serializer as DuperSerializer, }; use serde_core::{Serialize, ser}; @@ -246,7 +246,7 @@ impl<'ser, 'a> ser::Serializer for &'ser mut Serializer<'a> { fn serialize_f64(self, v: f64) -> Result { Ok(DuperValue::Float { identifier: None, - inner: v.into(), + inner: v, }) } diff --git a/duper/src/serde/temporal.rs b/duper/src/serde/temporal.rs index ced7108..2cfee5b 100644 --- a/duper/src/serde/temporal.rs +++ b/duper/src/serde/temporal.rs @@ -65,7 +65,6 @@ pub enum TemporalString<'a> { } impl TemporalString<'_> { - /// pub fn name(&self) -> &'static str { match self { TemporalString::Instant(_) => "Instant", diff --git a/duper/src/visitor/pretty_printer.rs b/duper/src/visitor/pretty_printer.rs index 6683294..8bd19f7 100644 --- a/duper/src/visitor/pretty_printer.rs +++ b/duper/src/visitor/pretty_printer.rs @@ -1,10 +1,12 @@ //! Utilities for pretty-printing Duper values. use crate::{ - ast::{DuperIdentifier, DuperObject, DuperValue, DuperTemporal}, format::{ + ast::{DuperIdentifier, DuperObject, DuperTemporal, DuperValue}, + format::{ format_boolean, format_duper_bytes, format_duper_string, format_float, format_integer, format_key, format_null, format_temporal, - }, visitor::DuperVisitor + }, + visitor::DuperVisitor, }; /// A Duper visitor which pretty-prints the provided [`DuperValue`] with @@ -166,7 +168,7 @@ impl<'pp> DuperVisitor for PrettyPrinter<'pp> { } else if tuple.len() == 1 { self.buf.push_str("(("); tuple - .get(0) + .first() .expect("tuple contains one element") .accept(self); self.buf.push_str("))"); @@ -187,7 +189,7 @@ impl<'pp> DuperVisitor for PrettyPrinter<'pp> { } else if tuple.len() == 1 { self.buf.push('('); tuple - .get(0) + .first() .expect("tuple contains one element") .accept(self); self.buf.push(')'); @@ -258,10 +260,7 @@ impl<'pp> DuperVisitor for PrettyPrinter<'pp> { } } - fn visit_temporal<'a>( - &mut self, - temporal: &DuperTemporal<'a>, - ) -> Self::Value { + fn visit_temporal<'a>(&mut self, temporal: &DuperTemporal<'a>) -> Self::Value { let identifier = temporal.identifier(); if !self.strip_identifiers && let Some(identifier) = identifier @@ -504,11 +503,10 @@ mod pretty_printer_tests { DuperIdentifier::try_from(Cow::Borrowed("Msg")) .expect("valid identifier"), ), - inner: + inner: Cow::Borrowed( "This is a very long string that will push itself into the next line.", ), - }, ), ( @@ -541,17 +539,13 @@ mod pretty_printer_tests { identifier: None, inner: vec![DuperValue::String { identifier: None, - inner: Cow::Borrowed( - "So many arrays!", - ), + inner: Cow::Borrowed("So many arrays!"), }], }], }, DuperValue::String { identifier: None, - inner: Cow::Borrowed( - r#""Hello world!""#, - ), + inner: Cow::Borrowed(r#""Hello world!""#), }, ], }; @@ -594,12 +588,11 @@ mod pretty_printer_tests { DuperIdentifier::try_from(Cow::Borrowed("Str")) .expect("valid identifier"), ), - inner: Cow::Borrowed( - "test", - ), + inner: Cow::Borrowed("test"), }, ), - ]).unwrap(), + ]) + .unwrap(), }, ), ( @@ -627,7 +620,8 @@ mod pretty_printer_tests { ], }, ), - ]).unwrap(), + ]) + .unwrap(), }; let pp = PrettyPrinter::new(true, " ").unwrap().pretty_print(&value); assert_snapshot!(pp); @@ -669,13 +663,12 @@ mod pretty_printer_tests { identifier: None, inner: false, }, - DuperValue::Null { - identifier: None, - }, + DuperValue::Null { identifier: None }, ], }, ), - ]).unwrap(), + ]) + .unwrap(), }, ), ( @@ -685,7 +678,8 @@ mod pretty_printer_tests { inner: Cow::Borrowed("value"), }, ), - ]).unwrap(), + ]) + .unwrap(), }; let pp = PrettyPrinter::new(false, "\t") .unwrap() diff --git a/duperq/src/types.rs b/duperq/src/types.rs index 5272d0e..b45f84c 100644 --- a/duperq/src/types.rs +++ b/duperq/src/types.rs @@ -69,7 +69,7 @@ impl DuperType { }, ) => Some(DuperValue::Array { identifier: identifier.clone(), - inner: tuple.iter().cloned().collect::>(), + inner: tuple.to_vec(), }), ( DuperType::Tuple, @@ -79,7 +79,7 @@ impl DuperType { }, ) => Some(DuperValue::Tuple { identifier: identifier.clone(), - inner: array.iter().cloned().collect::>(), + inner: array.to_vec(), }), ( DuperType::String, -- 2.51.2