Skip to content

Commit

Permalink
impl Copy for simple config enums (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Jun 10, 2024
1 parent 96aca52 commit 8afaa45
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/serializers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)*
Expand Down Expand Up @@ -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<PyObject> {
pub fn either_delta_to_json(self, py: Python, either_delta: &EitherTimedelta) -> PyResult<PyObject> {
match self {
Self::Iso8601 => {
let d = either_delta.to_duration()?;
Expand All @@ -128,7 +128,7 @@ impl TimedeltaMode {
}
}

pub fn json_key<'py>(&self, py: Python, either_delta: &EitherTimedelta) -> PyResult<Cow<'py, str>> {
pub fn json_key<'py>(self, py: Python, either_delta: &EitherTimedelta) -> PyResult<Cow<'py, str>> {
match self {
Self::Iso8601 => {
let d = either_delta.to_duration()?;
Expand All @@ -143,7 +143,7 @@ impl TimedeltaMode {
}

pub fn timedelta_serialize<S: serde::ser::Serializer>(
&self,
self,
py: Python,
either_delta: &EitherTimedelta,
serializer: S,
Expand All @@ -164,7 +164,7 @@ impl TimedeltaMode {
}

impl BytesMode {
pub fn bytes_to_string<'a>(&self, py: Python, bytes: &'a [u8]) -> PyResult<Cow<'a, str>> {
pub fn bytes_to_string<'a>(self, py: Python, bytes: &'a [u8]) -> PyResult<Cow<'a, str>> {
match self {
Self::Utf8 => from_utf8(bytes)
.map_err(|err| utf8_py_error(py, err, bytes))
Expand All @@ -176,7 +176,7 @@ impl BytesMode {
}
}

pub fn serialize_bytes<S: serde::ser::Serializer>(&self, bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
pub fn serialize_bytes<S: serde::ser::Serializer>(self, bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::Utf8 => match from_utf8(bytes) {
Ok(s) => serializer.serialize_str(s),
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub(crate) fn infer_serialize_known<S: Serializer>(
ObType::Bool => serialize!(bool),
ObType::Float | ObType::FloatSubclass => {
let v = value.extract::<f64>().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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/type_serializers/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl TypeSerializer for FloatSerializer {
extra: &Extra,
) -> Result<S::Ok, S::Error> {
match value.extract::<f64>() {
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::<S>(self.get_name(), value, extra)?;
infer_serialize(value, serializer, include, exclude, extra)
Expand Down

0 comments on commit 8afaa45

Please sign in to comment.