jonasbb / serde_with

This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
https://docs.rs/serde_with
Apache License 2.0
636 stars 67 forks source link

fix(serde_conv): allow `clippy::ptr_arg` #729

Closed mkroening closed 4 months ago

mkroening commented 4 months ago

This is https://github.com/jonasbb/serde_with/pull/320 again after the allow was removed in f3892d0.

This is the offending code that I have:

serde_with::serde_conv!(
    pub StringAsHtml,
    String,
    |string: &str| html_escape::encode_text(string).into_owned(),
    |html: String| -> Result<_, Infallible> {
        match html_escape::decode_html_entities(&html) {
            Cow::Owned(string) => Ok(string),
            Cow::Borrowed(_) => Ok(html),
        }
    }
);

This results in:

warning: writing `&String` instead of `&str` involves a new object where a slice will do
   --> serde_with/serde_with/src/serde_conv.rs:116:41
    |
107 |   macro_rules! serde_conv {
    |   ----------------------- in this expansion of `serde_with::serde_conv!`
...
116 |                   $vis fn serialize<S>(x: &$t, serializer: S) -> $crate::__private__::Result<S::Ok, S::Error>
    |                                           ^^^
    |
   ::: src/serde.rs:31:1
    |
31  | / serde_with::serde_conv!(
32  | |     pub StringAsHtml,
33  | |     String,
34  | |     |string: &str| html_escape::encode_text(string).into_owned(),
...   |
40  | |     }
41  | | );
    | |_- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
    = note: `#[warn(clippy::ptr_arg)]` on by default

I am not sure if there is a way to resolve the issue on my end. What do you think?

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 66.49%. Comparing base (f4145e3) to head (4a5a4ab). Report is 10 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #729 +/- ## ======================================= Coverage 66.49% 66.49% ======================================= Files 38 38 Lines 2468 2468 ======================================= Hits 1641 1641 Misses 827 827 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jonasbb commented 4 months ago

Sorry that it regressed. I added a test in #731 such that it hopefully doesn't regress anymore.