2 releases

0.1.2 Nov 28, 2020
0.1.0 Oct 3, 2020

#2445 in Rust patterns

Download history 783/week @ 2024-07-22 1580/week @ 2024-07-29 1239/week @ 2024-08-05 1412/week @ 2024-08-12 1514/week @ 2024-08-19 1132/week @ 2024-08-26 1514/week @ 2024-09-02 605/week @ 2024-09-09 1751/week @ 2024-09-16 613/week @ 2024-09-23 360/week @ 2024-09-30 1257/week @ 2024-10-07 1648/week @ 2024-10-14 554/week @ 2024-10-21 1353/week @ 2024-10-28 700/week @ 2024-11-04

4,754 downloads per month
Used in 65 crates (2 directly)

MIT license

10KB
107 lines

Serde string helpers

Build Tests Lints codecov MIT licensed

Rust crate containing helpers for using serde with strings.

About

Currently there is only a helper for deserializing stringly values more efficiently by avoiding allocation (and copying) in certain cases. New helpers may appear in the future.

This crate is no_std but does require alloc.

DeserBorrowStr

A helper for deserializing using TryFrom more efficiently.

When using #[serde(try_from = "String"] when deserializing a value that doesn't need to hold the string (e.g. an integer value) serde would allocate the string even if it doesn't have to. (Such as in the case of non-escaped Json string.)

A naive idea is to use std::borrow::Cow to solve it. Sadly, the implementation of Deserialize for Cow<'de, str> doesn't borrow the string, so it still allocates needlessly. This helper solves the issue.

Our DeserBorrowStr is written such that it borrows the str when possible, avoiding the allocation. It may still need to allocate, for example if string decoding (unescaping) has to be performed.

MSRV

The official MSRV is 1.41.1 for now and may be lowered later.

License

MIT

Dependencies

~0.3–1MB
~21K SLoC