#serde #cow #cow-str #borrowing #ways #deserializations #efficent

serde_cow

A library with more efficent serde deserializations for Cow

1 unstable release

0.1.0 Mar 24, 2024

#2100 in Parser implementations

Download history 432/week @ 2024-03-23 404/week @ 2024-03-30 329/week @ 2024-04-06

1,165 downloads per month

MIT license

5KB
82 lines

serde-cow

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


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!

Dependencies

~110–355KB