Crate soml

Crate soml 

Source
Expand description

A lightweight Serde-compatible TOML parser written in Rust

§but why?

The toml crate has lots of amazing features, but that makes it really heavy in terms of binary size and compile times. For one of my other projects toml accounted for over 15% of the compiled binary size despite only being used to read one small config file.

This project designed to sit at the opposite end of the spectrum, offering basic TOML support for Serde with a much smaller footprint. See the comparison table below for a more detailed comparison of TOML crates.

We also aim to be mostly API-compatibility with the toml crate, so migrating to (or from) soml should be relatively easy.

§Features

FeatureDefaultDescription
stdEnables std support
strictEnables extra checks for strict compliance with the TOML spec (see below)
datetimeEnables support for TOML date-time values

§The strict feature

The (enabled by default) strict feature adds certain checks required to validate compliance with the TOML spec. These checks can be disabled allowing the parser accept some unambiguous but not-technically-valid TOML. For some applications disabling the strict feature could yield a small performance improvement.

The following checks are currently disabled without the strict feature:

  • Validate comments are valid UTF-8
  • Scan comments for disallowed control characters
  • Range checking on date-time values
    • For example, 2024-14-35T25:61:63 is invalid

ℹ️ Important
The exact list of checks controlled by the strict feature is considered an implementation detail and is subject to change. Changes to which not-strictly-valid TOML is accepted when strict is disabled is not considered a breaking change.

§Comparison of TOML crates

These tables are autogenerated by binsize/main.py:

§Deserialize-only

CrateVersionSize *MaintainedTOML version
soml0.2.0103 KiB1.0
soml
(datetime disabled)
0.2.098 KiB1.0 †
toml0.9.5164 KiB1.0
toml0.8.23231 KiB1.0
toml0.5.11114 KiB0.5
basic-toml0.1.10117 KiB0.5 †

* Increase in code (.text) size compared to just reading/writing a file without (de)serializing. This is calculated using cargo-bloat with the default release profile.
Does not support TOML date-time types.

§Deserialize and Serialize

CrateVersionSize *MaintainedTOML version
soml0.2.0128 KiB1.0
soml
(datetime disabled)
0.2.0122 KiB1.0 †
toml0.9.5186 KiB1.0
toml0.8.23320 KiB1.0
toml0.5.11127 KiB0.5
basic-toml0.1.10127 KiB0.5 †

* Increase in code (.text) size compared to just reading/writing a file without (de)serializing. This is calculated using cargo-bloat with the default release profile.
Does not support TOML date-time types.

Modules§

de
TOML deserialization functions and trait implementations.
map
Generic TOML map types.
ser
TOML serialization functions and trait implementations.
value
Generic TOML value (de-)serialization.

Structs§

Deserializer
A deserializer for a TOML document.
Serializer
A serializer for a TOML document.

Enums§

Value
A generic TOML value type.

Functions§

from_reader
Deserialize a value of type T from an io::Read source.
from_slice
Deserialize a value of type T from a TOML byte slice.
from_str
Deserialize a value of type T from a TOML string slice.
to_string
Serializes a value to a TOML string.

Type Aliases§

Table
A TOML table type.