From 8afaa45190d4fb63d9b6d442944a02b06df09e5a Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 10 Jun 2024 13:53:55 +0100 Subject: [PATCH] impl `Copy` for simple config enums (#1325) --- src/serializers/config.rs | 12 ++++++------ src/serializers/infer.rs | 2 +- src/serializers/type_serializers/float.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/serializers/config.rs b/src/serializers/config.rs index 0aca33de5..5421ed920 100644 --- a/src/serializers/config.rs +++ b/src/serializers/config.rs @@ -51,7 +51,7 @@ pub trait FromConfig { macro_rules! serialization_mode { ($name:ident, $config_key:expr, $($variant:ident => $value:expr),* $(,)?) => { - #[derive(Default, Debug, Clone, PartialEq, Eq)] + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum $name { #[default] $($variant,)* @@ -112,7 +112,7 @@ impl TimedeltaMode { py_timedelta.call_method0(intern!(py_timedelta.py(), "total_seconds")) } - pub fn either_delta_to_json(&self, py: Python, either_delta: &EitherTimedelta) -> PyResult { + pub fn either_delta_to_json(self, py: Python, either_delta: &EitherTimedelta) -> PyResult { match self { Self::Iso8601 => { let d = either_delta.to_duration()?; @@ -128,7 +128,7 @@ impl TimedeltaMode { } } - pub fn json_key<'py>(&self, py: Python, either_delta: &EitherTimedelta) -> PyResult> { + pub fn json_key<'py>(self, py: Python, either_delta: &EitherTimedelta) -> PyResult> { match self { Self::Iso8601 => { let d = either_delta.to_duration()?; @@ -143,7 +143,7 @@ impl TimedeltaMode { } pub fn timedelta_serialize( - &self, + self, py: Python, either_delta: &EitherTimedelta, serializer: S, @@ -164,7 +164,7 @@ impl TimedeltaMode { } impl BytesMode { - pub fn bytes_to_string<'a>(&self, py: Python, bytes: &'a [u8]) -> PyResult> { + pub fn bytes_to_string<'a>(self, py: Python, bytes: &'a [u8]) -> PyResult> { match self { Self::Utf8 => from_utf8(bytes) .map_err(|err| utf8_py_error(py, err, bytes)) @@ -176,7 +176,7 @@ impl BytesMode { } } - pub fn serialize_bytes(&self, bytes: &[u8], serializer: S) -> Result { + pub fn serialize_bytes(self, bytes: &[u8], serializer: S) -> Result { match self { Self::Utf8 => match from_utf8(bytes) { Ok(s) => serializer.serialize_str(s), diff --git a/src/serializers/infer.rs b/src/serializers/infer.rs index c4cb8e9d9..45d8957bb 100644 --- a/src/serializers/infer.rs +++ b/src/serializers/infer.rs @@ -404,7 +404,7 @@ pub(crate) fn infer_serialize_known( ObType::Bool => serialize!(bool), ObType::Float | ObType::FloatSubclass => { let v = value.extract::().map_err(py_err_se_err)?; - type_serializers::float::serialize_f64(v, serializer, extra.config.inf_nan_mode.clone()) + type_serializers::float::serialize_f64(v, serializer, extra.config.inf_nan_mode) } ObType::Decimal => value.to_string().serialize(serializer), ObType::Str | ObType::StrSubclass => { diff --git a/src/serializers/type_serializers/float.rs b/src/serializers/type_serializers/float.rs index 84eae4ba0..13af9294c 100644 --- a/src/serializers/type_serializers/float.rs +++ b/src/serializers/type_serializers/float.rs @@ -107,7 +107,7 @@ impl TypeSerializer for FloatSerializer { extra: &Extra, ) -> Result { match value.extract::() { - Ok(v) => serialize_f64(v, serializer, self.inf_nan_mode.clone()), + Ok(v) => serialize_f64(v, serializer, self.inf_nan_mode), Err(_) => { extra.warnings.on_fallback_ser::(self.get_name(), value, extra)?; infer_serialize(value, serializer, include, exclude, extra)