Skip to main content

aube_util/
lib.rs

1pub mod adaptive;
2pub mod buf;
3pub mod cache;
4pub mod collections;
5pub mod concurrency;
6pub mod diag;
7pub mod diag_kernel;
8pub mod env;
9
10// Convenience re-exports of the diagnostics public API so binaries can
11// reference `aube_util::DiagConfig` instead of `aube_util::diag::DiagConfig`.
12pub use diag::{DiagConfig, Slot, Span, jstr};
13pub mod fs;
14pub mod fs_atomic;
15pub mod hash;
16pub mod http;
17pub mod identity;
18pub mod io;
19
20// Convenience re-exports so consumers can reference `aube_util::Embedder`
21// / `aube_util::embedder()` without naming the module.
22pub use identity::{AUBE, Embedder, cmd, embedder, prog, set_embedder};
23pub mod path;
24pub mod pkg;
25pub mod snapshot;
26pub mod url;
27
28use serde::{Deserialize, Deserializer};
29
30/// Deserialize npm platform fields (`os`, `cpu`, `libc`) from either a
31/// string or an array of strings. Missing fields, nulls, and non-string
32/// array entries mean "no constraint" and are dropped.
33pub fn string_or_seq<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
34where
35    D: Deserializer<'de>,
36{
37    let value = Option::<serde_json::Value>::deserialize(deserializer)?;
38    Ok(match value {
39        None | Some(serde_json::Value::Null) => Vec::new(),
40        Some(serde_json::Value::String(s)) => vec![s],
41        Some(serde_json::Value::Array(values)) => values
42            .into_iter()
43            .filter_map(|value| match value {
44                serde_json::Value::String(s) => Some(s),
45                _ => None,
46            })
47            .collect(),
48        Some(_) => Vec::new(),
49    })
50}