Skip to main content

Crate kanchi

Crate kanchi 

Source
Expand description

kanchi (感知 — “sensing / perception”) — a typed environment-discovery primitive for the pleme-io fleet.

Every GPU/terminal app faces the same domain: probe the host for the best-fit value, fall back to a documented default when it can’t, expose the result as a discoverable tier. Today each app hand-rolls, per axis, the identical trio:

pub const FALLBACK_X: T = ...;
pub fn detect_x() -> Option<T> { /* probe */ }
pub fn detect_x_or_fallback() -> T { detect_x().unwrap_or(FALLBACK_X) }

That is the shikumi discovered() tier — but hand-written, so it drifts (apps stub it out because it’s too costly) and re-vendors subtle platform FFI (NSScreen, sysctl, /proc/meminfo). kanchi collapses the whole domain into a declaration:

kanchi::defaxes! {
    /// Display-fit window size.
    window_dims: (u32, u32) = (1200, 800)
        => || kanchi::probe::screen_frac(0.60, (800, 600), (1600, 1100));
    /// DPR-aware font size.
    font_size: f32 = 14.0 => || kanchi::probe::dpr_font_size(14.0, 16.0);
}

Each line emits the full trio. The platform probes live once, in probe, cfg-gated and returning None off-platform so the resolver lands cleanly on the fallback.

Modules§

probe
Platform environment probes — cfg-gated FFI, extracted once for the whole fleet so no consumer re-vendors the NSScreen / sysctl / /proc dance. Every probe returns None off-platform / when unanswerable, so the defaxes!-generated resolver lands cleanly on the fallback.

Macros§

defaxes
Declare environment-detection axes. One line per axis generates a documented FALLBACK_<NAME> const, a detect_<name>() -> Option<T> probe wrapper, and a detect_<name>_or_fallback() -> T resolver.

Functions§

clamp
Clamp v into [lo, hi] (probes use it to keep detected values sane).
none
Probe placeholder for an axis whose detection isn’t wired yet: always None, so detect_*_or_fallback() returns the documented fallback. Beats a hand-written stub — the axis still participates in the trio.