Skip to main content

Module settings_file

Module settings_file 

Source
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§

ReadError
Why a settings file could not be read. The file is left exactly as it is.
UpdateError
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. None when the text is not one object.
merge_into_template
Merge user settings into a JSONC template string.
parse
bytes as 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, let change edit the values, and write the file with the changes made where they belong in its own text, and its commented defaults brought up to template.
write_atomic
Write contents to path so 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.