• v1.1.0 eac3a60e9e

    v1.1.0 Stable

    petrbalvin released this 2026-06-26 18:12:15 +00:00 | 3 commits to main since this release

    Adds TOML emission to the previously read-only library, completing the
    encoding/json-style API.

    Added

    Marshalling

    • Marshal(v any) ([]byte, error) — encode a struct or map[string]V value
      to a TOML 1.0 document.
    • Encoder and NewEncoder, mirroring the Decoder shape for symmetry with
      Unmarshal.
    • Marshaler interface (MarshalTOML() (any, error)) for types that need a
      custom TOML shape; the returned value is encoded normally.
    • Struct fields are matched by toml:"name" tag (case-insensitive fallback to
      field name; toml:"-" skips). Anonymous (embedded) fields without a tag
      are inlined.
    • Slices and arrays of structs or maps become [[a]] arrays of tables; other
      slices and arrays become TOML arrays. Empty or nil arrays of tables are
      omitted; empty arrays of scalars emit as key = [].
    • Scalars encode as bool, int64, float64, string, time.Time (offset
      date-time), LocalDateTime, LocalDate, or LocalTime.
    • time.Time, LocalDateTime, LocalDate, and LocalTime now have
      String() methods that return their TOML-canonical rendering
      (zero-padded to nanosecond precision when a fractional second is present).

    Encoding policy

    The emitter groups fields at every TOML level: scalars first, then
    sub-tables, then arrays of tables. Within each group the order matches struct
    field declaration order, or sorted key order for maps. The output is
    guaranteed to re-parse to an equivalent value tree via Parse, but is not
    byte-identical to any input that produced the value — comments, whitespace,
    map key order, and basic-vs-literal string quoting are not preserved. See
    the "Encoding" section of the README for the full set of rules.

    Downloads