docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#NABION configuration

本页内容

Read a NABION configuration into #[derive(Nabion)] structs with defaults filled in, validate it, change it and write it back as NABION.

#Code

#Walkthrough

  • A single #[derive(Nabion)] makes structs and enums convert to and from NABION. A nested struct (Listen), an enum (Level), List, Dict and Tls | none all map directly (NABION, 3.8.2 mapping to Nabi types).
  • Fields missing from the document take the struct's default (workers: i32 = 4); a T | none field without a default becomes none. Nested values written without a type name, like listen: { port: 9000 }, are accepted too.
  • nabion::from_str throws a NabionError for a value of the wrong type, with a line:col position in the message. A field the type does not have is skipped by default; #[nabion(deny_unknown_fields)] on Config makes it an error, so a typo such as wokers is not silently ignored (nabion::from_str).
  • Rules beyond the format (port must not be 0, worker count in range) are collected by validate and reported together. Whether a T | none value is empty is checked with c.tls is none.
  • nabion::to_str writes the canonical form, and throws for a value with no NABION form (a NaN float). Fields filled from defaults are written out too, so reading the output gives the same value back. A Dict keeps its key order, so the limits come out in the order they were read (nabion::to_str).

Found a mistake? Edit this page on GitHub. Last updated