Expand description
Writing settings.json without losing what the person put in it
(docs/specs/SPEC_SETTINGS_JSON_EVERY_KEY_ONE_TO_ONE_2026_11_01.md §3, §5.4).
The launcher’s startup seed, srv’s setting changes and the migrations all rewrite the file from the template plus the person’s values. They used to read the file leniently (a file that did not parse read as “no settings”) and write the result, so a half-pasted file, a missing comma or a byte-order mark replaced everything the person had set with the bare template. Here a file that cannot be read is never written, a write is atomic, and writers do not interleave.
Structs§
- Loaded
- A settings file as read: its values, and the byte-level habits to write back.
Enums§
- Read
Error - Why a settings file could not be read. The file is left exactly as it is.
- Update
Error - Why a write did not happen. The file is left as it was.
Constants§
- MAX_
SETTINGS_ BYTES - Settings files are a few KiB. Anything past this is not one, and is left alone.
Functions§
- key_
lines - The 1-based line each top-level key of a settings file’s text is written on, to say where a
problem is.
Nonewhen the text is not one object. - merge_
into_ template - Merge user settings into a JSONC template string.
- parse
bytesas a settings file: JSONC (comments and trailing commas allowed), one object. An empty or blank file holds no settings.- read
- The settings file at
path:Ok(None)when there is none. - update
- Read the settings at
path, letchangeedit the values, and write the file with the changes made where they belong in its own text, and its commented defaults brought up totemplate. - write_
atomic - Write
contentstopathso a reader sees the old file or the new one, never a short one: a temporary file in the same folder, flushed, then renamed over it.