Serde: Support for atomics data types?

Created on 15 Mar 2019  路  5Comments  路  Source: serde-rs/serde

Hi,

it seems like there is no Serialize support for atomic data type: https://doc.rust-lang.org/core/sync/atomic/index.html

Is there any reason for this?

A first implementation would be to simply load them using Ordering::Relaxed and that should be quite enough.

Most helpful comment

I believe #1572 solves this (and is ready for review).

All 5 comments

I would prefer to match Debug which uses Ordering::SeqCst.
https://github.com/rust-lang/rust/blob/1.33.0/src/libcore/sync/atomic.rs#L1137-L1141

I would be prepared to consider a PR adding impls that use SeqCst.

SeqCst is the strongest guarantee possible. This is ok and maybe even desiderable in debugging code, but I am not sure is desiderable on production code.

What is your take on this?

Do you believe performance won't be a concern? I am not sure of the performance characteristics of serde (never used) so I am really asking a little more feedback on your thoughts!

Cheers

If someone observes serialization of atomics as a bottleneck, they can use a serialize_with attribute to substitute in a Serialize impl with a weaker guarantee. SeqCst is a safe default with the least surprises and frequently no different performance.

I am not sure if I got the time to do this anyway, I don't believe in the next few weeks at the very least.

If anybody wants to jump on it feel free to just implement it!

I believe #1572 solves this (and is ready for review).

Was this page helpful?
0 / 5 - 0 ratings