#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

#2387 in Parser implementations

Download history 6335/week @ 2024-11-16 6575/week @ 2024-11-23 6956/week @ 2024-11-30 5576/week @ 2024-12-07 5791/week @ 2024-12-14 5317/week @ 2024-12-21 5544/week @ 2024-12-28 7892/week @ 2025-01-04 7419/week @ 2025-01-11 5296/week @ 2025-01-18 3481/week @ 2025-01-25 4546/week @ 2025-02-01 4463/week @ 2025-02-08 4607/week @ 2025-02-15 4778/week @ 2025-02-22 4875/week @ 2025-03-01

19,428 downloads per month
Used in 44 crates (2 directly)

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

~99–325KB