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 terminal;
27pub mod url;
28
29use serde::{Deserialize, Deserializer};
30
31/// Deserialize npm platform fields (`os`, `cpu`, `libc`) from either a
32/// string or an array of strings. Missing fields, nulls, and non-string
33/// array entries mean "no constraint" and are dropped.
34pub fn string_or_seq<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
35where
36    D: Deserializer<'de>,
37{
38    let value = Option::<serde_json::Value>::deserialize(deserializer)?;
39    Ok(match value {
40        None | Some(serde_json::Value::Null) => Vec::new(),
41        Some(serde_json::Value::String(s)) => vec![s],
42        Some(serde_json::Value::Array(values)) => values
43            .into_iter()
44            .filter_map(|value| match value {
45                serde_json::Value::String(s) => Some(s),
46                _ => None,
47            })
48            .collect(),
49        Some(_) => Vec::new(),
50    })
51}