chrony-confile 0.1.0

A full-featured Rust library for parsing, editing, validating, and serializing chrony configuration files
Documentation
#![deny(unsafe_code)]
#![doc = "A full-featured Rust library for parsing, editing, validating, and serializing [chrony](https://chrony-project.org/) configuration files.\n\
\n\
This crate provides complete coverage of all 96 chrony directives with a type-safe API,\n\
lossless round-trip serialization (comments and formatting preserved), and optional\n\
`include`/`confdir` expansion.\n\
\n\
# Quick Start\n\
\n\
```rust\n\
use chrony_confile::prelude::*;\n\
\n\
let config: ChronyConfig = r#\"\n\
    server ntp1.example.com iburst prefer\n \
    server ntp2.example.com iburst\n \
    pool pool.ntp.org maxsources 6\n \
    driftfile /var/lib/chrony/drift\n \
    allow 192.168.0.0/16\n \
\"#.parse()?;\n\
\n\
// Iterate over directives with a specific name\n\
for directive in config.find(\"server\") {\n\
    if let DirectiveKind::Server(s) = &directive.kind {\n\
        println!(\"NTP source: {}\", s.hostname);\n\
    }\n\
}\n\
\n\
// Validate the configuration\n\
let errors = config.validate();\n\
\n\
// Serialize back to string (lossless)\n\
let output = config.to_string();\n\
# Ok::<_, chrony_confile::ParseError>(())\n\
```\n\
\n\
# Modules\n\
\n\
- **`ast`** -- All AST types representing chrony directives and configuration structure\n\
- **`parser`** -- Parsing logic for chrony config files and .sources files\n\
- **`ser`** -- Serialization (`Display` trait impls, optional `serde`)\n\
- **`validator`** -- Structural and semantic validation\n\
- **`builder`** -- Builder pattern for programmatic config generation\n\
- **`expand`** -- Include/confdir expansion\n\
- **`error`** -- Error types for parsing, validation, and value construction\n\
- **`span`** -- Source location tracking\n\
- **`values`** -- Bounded integer newtypes with range checking\n\
\n\
# Feature Flags\n\
\n\
- `serde` (optional) -- Enables `Serialize` for `ChronyConfig`\n\
"]

pub mod error;
pub mod span;
pub mod values;
pub mod ast;
pub mod parser;
pub mod ser;
pub mod validator;
pub mod builder;
pub mod expand;

// --- Core re-exports ---
pub use ast::ChronyConfig;
pub use ast::source_file::SourceFile;
pub use error::{ParseError, DirectiveError, ValueError};
pub use span::Span;
pub use ast::Directive;
pub use ast::DirectiveKind;
pub use ast::DirectiveCategory;
pub use ast::ConfigNode;

// --- Value types ---
pub use values::{
    PollInterval, UdpPort, Dscp, Stratum, SamplesCount, PollTarget,
    NtpVersion, PpsRate, SchedPriority, PtpDomain, ClientLogSize,
    TxBuffers, NtsProcesses,
};

// --- Source types ---
pub use ast::source::{
    ServerConfig, PoolConfig, PeerConfig, RefClockConfig, RefClockDriverKind,
    SourceConnectivity, AddressFamily, SelectOptions, AllowDenyConfig,
    RateLimitConfig, NtsRateLimitConfig, SmoothTimeConfig, BroadcastConfig,
    LocalConfig, InitStepSlewConfig,
};

// --- NTP config types ---
pub use ast::ntp::{
    BindAddressConfig, BindDeviceConfig, ClientLogLimitConfig,
    NtpSignDSocketConfig, NtsPortConfig, NtsServerCertConfig,
    NtsServerKeyConfig, NtsProcessesConfig, MaxNtsConnectionsConfig,
    NtsNtpServerConfig, NtsRotateConfig, PortConfig, CmdRateLimitConfig,
};

// --- Command access types ---
pub use ast::cmd::{
    BindCmdAddressConfig, BindCmdDeviceConfig, CmdPortConfig,
    OpenCommandsConfig,
};

// --- Clock types ---
pub use ast::clock::{
    ClockPrecisionConfig, CorrTimeRatioConfig, DriftFileConfig,
    FallbackDriftConfig, LeapSecTzConfig, LeapSecListConfig,
    MakeStepConfig, MaxChangeConfig, MaxClockErrorConfig, MaxDriftConfig,
    MaxUpdateSkewConfig, MaxSlewRateConfig, TempCompConfig,
    LeapSecMode,
};

// --- Selection types ---
pub use ast::selection::{
    AuthSelectMode, CombineLimitConfig, MaxDistanceConfig, MaxJitterConfig,
    MinSourcesConfig, ReselectDistConfig, StratumWeightConfig,
};

// --- Log types ---
pub use ast::log::{
    LogConfig, LogBannerConfig, LogChangeConfig, LogDirConfig,
};

// --- RTC types ---
pub use ast::rtc::{
    HwClockFileConfig, RtcAutoTrimConfig, RtcDeviceConfig, RtcFileConfig,
};

// --- HW timestamp types ---
pub use ast::hw::{
    HwTimestampConfig, HwTsTimeoutConfig, MaxTxBuffersConfig,
    PtpPortConfig, PtpDomainConfig, HwTsRxFilter,
};

// --- NTS types ---
pub use ast::nts::NtsAeadsConfig;

// --- Misc types ---
pub use ast::misc::{
    ConfDirConfig, IncludeConfig, SourceDirConfig, MailOnChangeConfig,
    PidFileConfig, SchedPriorityConfig, UserConfig, KeyFileConfig,
    AcquisitionPortConfig, DscpConfig, DumpDirConfig, NtsDumpDirConfig,
    NtsRefreshConfig, NtsTrustedCertsConfig, NoCertTimeCheckConfig,
    RefreshConfig, MaxSamplesConfig, MinSamplesConfig,
};

// --- Source file types ---
pub use ast::source_file::{SourceEntry, SourceNode};

// --- Builder types ---
pub use builder::{ServerBuilder, PoolBuilder};

// --- Expand types ---
pub use expand::ExpandOptions;

// --- FromStr impl ---

impl std::str::FromStr for ChronyConfig {
    type Err = ParseError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::parse(s)
    }
}

/// Convenience prelude for glob-importing the most common types.
///
/// ```rust
/// use chrony_confile::prelude::*;
/// ```
pub mod prelude {
    pub use crate::ast::*;
    pub use crate::builder::*;
    pub use crate::error::*;
    pub use crate::span::*;
    pub use crate::values::*;
    pub use crate::validator::Validate;
    pub use crate::ChronyConfig;
    pub use crate::SourceFile;
    pub use std::str::FromStr;
}