1 unstable release

Uses new Rust 2024

0.1.0 Aug 4, 2025

#2317 in Procedural macros

MIT/Apache

91KB
1.5K SLoC

oh_my_toml

This is a template for my Rust projects.

Installation

Supported platforms: Linux, macOS and Windows

Shell

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/nik-rev/oh_my_toml/releases/latest/download/oh_my_toml-installer.sh | sh

PowerShell

powershell -ExecutionPolicy Bypass -c "irm https://github.com/nik-rev/oh_my_toml/releases/latest/download/oh_my_toml-installer.ps1 | iex"

Homebrew

brew install nik-rev/tap/oh_my_toml

Cargo

cargo install oh_my_toml

Nix

nix profile install github:nik-rev/oh_my_toml/main

License

This repository is licensed under either of:

at your option.


lib.rs:

This crate contains the OhMyToml derive macro

Attributes

Field attributes

  • default or default = value: If the field is missing then the default value for the field will be used
  • on_default = "error": If the default value is used, then an error will be reported - but we still get our data. This allows for error recovery.
  • rename = "...": Renames this field. When checking for keys in the TOML, we will expect the renamed value.

Container attributes

  • default_all: Applies default to each field
    • To opt-out for a single field, use require
  • on_default_all = "error": Applies on_default = "error" to each field
    • To opt-out for a single field, use on_default = "ok" on the field
  • rename_all = "...": Renames all fields to use a different case. Available cases are:
    • "lowercase"
    • "UPPERCASE"
    • "PascalCase"
    • "camelCase"
    • "snake_case"
    • "SCREAMING_SNAKE_CASE"
    • "kebab-case"
    • "SCREAMING-KEBAB-CASE"
    • "Train-Case"
    • "Title Case"

Implementations

The DeserializeItem and DeserializeValue are implemented for the following types:

Implementations provided

Additionally, we provide Spanned<T> which allows you to wrap any type that can be deserialized from TOML to obtain its SourceSpan that represents the location of the type in the TOML file itself - to use as you please.

Dependencies

~14MB
~256K SLoC