Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2bd committed Jun 6, 2024
1 parent 96207a9 commit 34da11b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions serde-reflection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ use the crate [`serde-name`](https://crates.io/crates/serde-name) and its adapte
terminate. (Work around: re-order the variants. For instance `enum List {
Some(Box<List>), None}` must be rewritten `enum List { None, Some(Box<List>)}`.)

* Certain standard types such as `std::num::NonZeroU8` may not be tracked as a
container and appear simply as their underlying primitive type (e.g. `u8`) in the
formats. This loss of information makes it difficult to use `trace_value` to work
around deserialization invariants (see example below). As a work around, you may
override the default for the primitive type using `TracerConfig` (e.g. `let config =
TracerConfig::default().default_u8_value(1);`).

### Security CAVEAT

At this time, `HashSet<T>` and `BTreeSet<T>` are treated as sequences (i.e. vectors)
Expand Down
7 changes: 7 additions & 0 deletions serde-reflection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
//! terminate. (Work around: re-order the variants. For instance `enum List {
//! Some(Box<List>), None}` must be rewritten `enum List { None, Some(Box<List>)}`.)
//!
//! * Certain standard types such as `std::num::NonZeroU8` may not be tracked as a
//! container and appear simply as their underlying primitive type (e.g. `u8`) in the
//! formats. This loss of information makes it difficult to use `trace_value` to work
//! around deserialization invariants (see example below). As a work around, you may
//! override the default for the primitive type using `TracerConfig` (e.g. `let config =
//! TracerConfig::default().default_u8_value(1);`).
//!
//! ## Security CAVEAT
//!
//! At this time, `HashSet<T>` and `BTreeSet<T>` are treated as sequences (i.e. vectors)
Expand Down
6 changes: 6 additions & 0 deletions serde-reflection/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ fn test_default_value_for_primitive_types() {
let mut tracer = Tracer::new(config);
let samples = Samples::new();

let (format, value) = tracer
.trace_type_once::<std::num::NonZeroU8>(&samples)
.unwrap();
assert_eq!(format, Format::U8); // Not a container
assert_eq!(value.get(), 1);

let (format, value) = tracer.trace_type_once::<u8>(&samples).unwrap();
assert_eq!(format, Format::U8);
assert_eq!(value, 1);
Expand Down

0 comments on commit 34da11b

Please sign in to comment.