Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strong types for key and bare item integer, decimal, token, and string #137

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

apasel422
Copy link
Collaborator

@apasel422 apasel422 commented Feb 20, 2025

This is an updated version of #102 that takes the following approach:

  1. BareItem and RefBareItem contain only fully validated types.
  2. Dictionary and parameter keys are likewise fully validated.
  3. A number of helpers based on Into and TryInto simplify creation of these types from unvalidated inputs, including at compile-time using const fn.
  4. Parsing produces these fully validated types.
  5. Serialization accepts only these fully validated types, making serialization in general infallible (the only real errors being empty list and empty dictionary) and presumably improving performance in the likely common case that components are fully validated at compile time.
  6. rust_decimal::Decimal is replaced with an sfv::Decimal type that simply wraps the new Integer type, as an SFV decimal is 12 integral digits and 3 fractional digits, while an SFV integer is 15 decimal digits.
  7. The new sfv::{Key, String, Token} types are the owned equivalents of the new sfv::{KeyRef, StringRef, TokenRef} types, analogous to Vec<T> vs [T].

As part of #119, we will likewise introduce an sfv::Date type that wraps Integer.

Fixes #98

This makes integer serialization infallible.
This makes token serialization infallible.
This makes string serialization infallible.
This makes key serialization infallible.
We remove the rust_decimal dependency and use scaled integers instead.

This makes decimal and all bare-item serialization infallible.
This enables us to use structure-aware fuzzing for more efficient
coverage of serialize/parse roundtripping.

https://rust-fuzz.github.io/book/cargo-fuzz/structure-aware-fuzzing.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation of Items on local contruction
1 participant