gai_core/lib.rs
1//! gai-core: pure logic for parsing the OS name-resolution configuration
2//! and simulating the getaddrinfo() decision path.
3//!
4//! No network I/O, no process interception. Everything here is testable
5//! against fixture files, which is the whole point of keeping it separate
6//! from gai-probe, which supplies real answers over the network/D-Bus.
7//!
8//! # Example
9//!
10//! ```
11//! use gai_core::sim::{simulate, SourceResolver};
12//! use gai_core::types::{NssEntry, NssSource, NsswitchConfig, StepResult};
13//!
14//! // A resolver that always finds an answer via DNS — in real use this
15//! // would be gai-probe's SystemSourceResolver, doing actual I/O.
16//! struct AlwaysDns;
17//! impl SourceResolver for AlwaysDns {
18//! fn resolve(&mut self, source: &NssSource, _name: &str) -> StepResult {
19//! match source {
20//! NssSource::Dns => StepResult::Found(vec!["93.184.216.34".parse().unwrap()]),
21//! _ => StepResult::NotFound,
22//! }
23//! }
24//! }
25//!
26//! let config = NsswitchConfig {
27//! hosts: vec![
28//! NssEntry { source: NssSource::Files, criteria: vec![] },
29//! NssEntry { source: NssSource::Dns, criteria: vec![] },
30//! ],
31//! };
32//!
33//! let outcome = simulate(&config, "example.com", &mut AlwaysDns);
34//! assert!(outcome.resolved());
35//! assert_eq!(outcome.steps.len(), 2, "files was tried and fell through to dns");
36//! ```
37
38pub mod config;
39pub mod platform;
40pub mod sim;
41pub mod types;
42
43pub use sim::{simulate, SimulationOutcome};
44pub use types::*;