zsfm_core/cfgval.rs
1//! Small helpers for pulling `InferConfig` fields out of a HuggingFace `config.json`
2//! `serde_json::Value` with a default fallback — the same `.as_u64().unwrap_or(N) as usize`
3//! shape every model's config-loading code (CLI, and later Python bindings) needs.
4
5pub fn json_usize(v: &serde_json::Value, key: &str, default: usize) -> usize {
6 v[key].as_u64().map(|n| n as usize).unwrap_or(default)
7}
8
9pub fn json_f64(v: &serde_json::Value, key: &str, default: f64) -> f64 {
10 v[key].as_f64().unwrap_or(default)
11}
12
13pub fn json_bool(v: &serde_json::Value, key: &str, default: bool) -> bool {
14 v[key].as_bool().unwrap_or(default)
15}