Thanks to visit codestin.com
Credit goes to lib.rs

#serialization #partial-eq #array #deserialize

deduplicating_array

A serde serialization strategy that uses PartialEq to reduce serialized size

10 releases

0.1.10 Sep 11, 2025
0.1.8 Feb 26, 2025
0.1.7 Nov 23, 2024
0.1.6 May 28, 2024
0.1.0 Jan 31, 2022

#319 in Encoding

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

1,530 downloads per month

Unicode-3.0

14KB
223 lines

deduplicating_array crates.io

A serde serialization strategy that uses PartialEq to reduce serialized size.

This crate works, but does not currently have a GitHub repo since the ICU4X project is not using it anymore.

This create can be used with Serde derive like this:


#[derive(serde::Deserialize, serde::Serialize)]
pub struct Foo {
    #[serde(with = "deduplicating_array")]
    data: [Bar; 12],
    // ...
}

Bars that are equal to a Bars that appears earlier in the array will not be serialized (instead, the index of the first occurence is serialized). Deserialization clones the first Bar into all the indices where it occurs (hence Bar has to implement Clone).

Human readable serialization represents skipped values as singleton arrays containing the target index, e.g. the Rust array ["Foo", "Bar", "Foo"] will serialize to JSON ["Foo", "Bar", [0]].

This implies that singleton integer arrays cannot be used as array elements (they do work in Bincode, but there's really not much point in using them).

Dependencies

~0.3–1MB
~22K SLoC