vorner / arc-swap

Support atomic operations on Arc itself
Apache License 2.0
778 stars 31 forks source link

Add serialize / deserialize features. #65

Closed BratSinot closed 2 years ago

BratSinot commented 2 years ago

46

Greetings,

Realization is optional (through features). For me such feature needed to get rid of tons of manual Deserializations / Serializations like this:

use arc_swap::ArcSwap;

#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Foo {
    field0: ArcSwap<usize>,
    field1: ArcSwap<String>,
}

fn main() {
    let data = Foo {
        field0: ArcSwap::from_pointee(123),
        field1: ArcSwap::from_pointee("FOO".to_owned()),
    };

    println!("{}", serde_json::to_string(&data).unwrap());
}
vorner commented 2 years ago

46 was waiting for someone just like you, having the motivation to get around to this :-). I'll give it a proper read later today and see what the CI says.

I just wonder if two features are needed (while they both bring serde in, which is the big chunk), or if single serde one would be enough.

codecov-commenter commented 2 years ago

Codecov Report

Merging #65 (3cfc699) into master (13e5e3f) will increase coverage by 0.68%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   85.56%   86.25%   +0.68%     
==========================================
  Files          17       18       +1     
  Lines        1032     1091      +59     
==========================================
+ Hits          883      941      +58     
- Misses        149      150       +1     
Impacted Files Coverage Δ
src/lib.rs 94.81% <ø> (-0.31%) :arrow_down:
src/serde.rs 100.00% <100.00%> (ø)
BratSinot commented 2 years ago

OK, I'm mostly happy about it. Clippy and rustfmt aren't, and the history is a bit cluttered. Is it fine with you if I just take it over and deal with these "formalities" (I'll be dealing with a release anyway)?

Yeah, of course.

I saw you using nightly? Maybe this make some difference. I also use Clippy and rustfmt (by default in my fav IDE), maybe there was some kind of glitch in my IDE.

Ow, it wasn't IDE glitch, it was IDE old settings "glitch" =)