Crate noml

Source
Expand description

§NOML - Nested Object Markup Language

NOML is a modern configuration language that combines the simplicity of TOML with advanced features like environment variables, file inclusion, variable interpolation, and native types.

§Quick Start

use noml::{parse, Value};
 
let source = r#"
    name = "my-app"
    version = "1.0.0"
    debug = true
     
    database_url = env("DATABASE_URL", "sqlite:memory:")
     
    max_file_size = @size("10MB")
    timeout = @duration("30s")
     
    [server]
    host = "0.0.0.0"
    port = 8080
     
    [database]
    host = "localhost"
    port = 5432
"#;
 
let config = parse(source)?;
 
// Access values
assert_eq!(config.get("name").unwrap().as_string().unwrap(), "my-app");
assert_eq!(config.get("server.port").unwrap().as_integer().unwrap(), 8080);
 

§Features

  • TOML-compatible syntax with additional features
  • Environment variables via env("VAR_NAME", "default")
  • File inclusion via include "path/to/file.noml"
  • Variable interpolation via "Hello ${name}!"
  • Native types like @size("10MB") and @duration("30s")
  • Comment preservation for tooling and round-trip editing
  • Detailed error reporting with source locations
  • Zero-copy parsing for performance

§Advanced Usage

use noml::{Resolver, ResolverConfig, parse_string};
use std::collections::HashMap;
 
// Custom environment variables
let mut env_vars = HashMap::new();
env_vars.insert("APP_NAME".to_string(), "my-app".to_string());
 
// Custom resolver configuration
let config = ResolverConfig {
    env_vars: Some(env_vars),
    allow_missing_env: true,
    ..Default::default()
};
 
let mut resolver = Resolver::with_config(config);
let document = parse_string(r#"name = env("APP_NAME")"#, None)?;
let value = resolver.resolve(document)?;
 
assert_eq!(value.get("name").unwrap().as_string().unwrap(), "my-app");
 

Re-exports§

pub use error::NomlError;
pub use error::Result;
pub use parser::parse_string;
pub use parser::parse_file;
pub use parser::Document;
pub use value::Value;
pub use resolver::Resolver;
pub use resolver::ResolverConfig;
pub use resolver::NativeResolver;

Modules§

error
Error Handling
parser
NOML Parser Module
resolver
NOML Resolver
value
NOML Value System

Functions§

parse
Parse NOML from a string and resolve all dynamic features
parse_from_file
Parse NOML from a file and resolve all dynamic features
parse_raw
Parse NOML from a string without resolving dynamic features
parse_raw_from_file
Parse NOML from a file without resolving dynamic features
validate
Validate NOML syntax without parsing into values