#deserialize #cow #serde #string #optimization

no-std serde_cow

A library with more efficent serde deserializations for Cow

3 releases

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

#2378 in Parser implementations

Download history 5407/week @ 2024-10-23 5098/week @ 2024-10-30 4611/week @ 2024-11-06 7403/week @ 2024-11-13 6591/week @ 2024-11-20 6384/week @ 2024-11-27 6542/week @ 2024-12-04 5657/week @ 2024-12-11 5709/week @ 2024-12-18 5169/week @ 2024-12-25 6956/week @ 2025-01-01 7147/week @ 2025-01-08 6774/week @ 2025-01-15 3957/week @ 2025-01-22 4067/week @ 2025-01-29 3998/week @ 2025-02-05

19,658 downloads per month
Used in 41 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

~100–325KB