#cow #deserialize #serde #string #optimization

no-std serde_cow

A library with more efficent serde deserializations for Cow

3 releases

new 0.1.2 Jul 17, 2024
0.1.1 Jul 17, 2024
0.1.0 Mar 24, 2024

#1 in #optimisation

Download history 516/week @ 2024-03-27 141/week @ 2024-04-03 369/week @ 2024-04-10 239/week @ 2024-04-17 613/week @ 2024-04-24 549/week @ 2024-05-01 307/week @ 2024-05-08 368/week @ 2024-05-15 581/week @ 2024-05-22 1110/week @ 2024-05-29 1576/week @ 2024-06-05 1946/week @ 2024-06-12 1863/week @ 2024-06-19 1846/week @ 2024-06-26 1753/week @ 2024-07-03 2819/week @ 2024-07-10

8,642 downloads per month
Used in 23 crates (via serenity)

MIT license

6KB
84 lines

serde-cow

See the documentation on docs.rs or build locally with cargo doc --no-deps --open.

Minimum Supported Rust Version

This is currently 1.56 and is considered a breaking change to increase.


lib.rs:

A small library with a [Cow] wrappers that implements serde::Deserialize in the ways that should be expected.

By default, [Cow] is always deserialized to the Cow::Owned variant due to a lack of specialisation, but this library provides CowStr and CowBytes which deserialize to Cow::Borrowed if possible, borrowing from the original data.

Example

use std::borrow::Cow;

use serde_cow::CowStr;

let source = r#""Hello World""#;

let normal: Cow<str> = serde_json::from_str(source).unwrap();
assert!(matches!(normal, Cow::Owned(_))); // Wasteful!

let efficent: CowStr = serde_json::from_str(source).unwrap();
assert!(matches!(efficent.0, Cow::Borrowed(_))); // Zero copy!

Minimum Supported Rust Version

This is currently 1.56 and is considered a breaking change to increase.

Dependencies

~110–350KB