Skip to main content

nova_std/
lib.rs

1//! The sources of Nova's standard library, `std/*/lib.nova`, embedded at
2//! build time so the compiler stays one self-contained executable.
3//!
4//! Every `include_str!` path stays inside this package, so `cargo package`
5//! carries all 17 files, and its verification step builds the packaged copy
6//! on its own (spec
7//! `docs/superpowers/specs/2026-10-07-phase-3-0-foundations-design.md` ยง3).
8//! `nova-resolver` gives each module its `$std.*` name and its place.
9
10/// `std/bytes/lib.nova`.
11pub const BYTES: &str = include_str!("bytes/lib.nova");
12/// `std/collections/lib.nova`.
13pub const COLLECTIONS: &str = include_str!("collections/lib.nova");
14/// `std/core/lib.nova`.
15pub const CORE: &str = include_str!("core/lib.nova");
16/// `std/crypto/lib.nova`.
17pub const CRYPTO: &str = include_str!("crypto/lib.nova");
18/// `std/fmt/lib.nova`.
19pub const FMT: &str = include_str!("fmt/lib.nova");
20/// `std/fs/lib.nova`.
21pub const FS: &str = include_str!("fs/lib.nova");
22/// `std/http/lib.nova`.
23pub const HTTP: &str = include_str!("http/lib.nova");
24/// `std/io/lib.nova`.
25pub const IO: &str = include_str!("io/lib.nova");
26/// `std/json/lib.nova`.
27pub const JSON: &str = include_str!("json/lib.nova");
28/// `std/log/lib.nova`.
29pub const LOG: &str = include_str!("log/lib.nova");
30/// `std/net/lib.nova`.
31pub const NET: &str = include_str!("net/lib.nova");
32/// `std/process/lib.nova`.
33pub const PROCESS: &str = include_str!("process/lib.nova");
34/// `std/strings/lib.nova`.
35pub const STRINGS: &str = include_str!("strings/lib.nova");
36/// `std/sync/lib.nova`.
37pub const SYNC: &str = include_str!("sync/lib.nova");
38/// `std/task/lib.nova`.
39pub const TASK: &str = include_str!("task/lib.nova");
40/// `std/test/lib.nova`, seeded only under `nova test`.
41pub const TEST: &str = include_str!("test/lib.nova");
42/// `std/time/lib.nova`.
43pub const TIME: &str = include_str!("time/lib.nova");
44
45/// Every embedded module, by its directory under `std/`.
46pub const ALL: [(&str, &str); 17] = [
47    ("bytes", BYTES),
48    ("collections", COLLECTIONS),
49    ("core", CORE),
50    ("crypto", CRYPTO),
51    ("fmt", FMT),
52    ("fs", FS),
53    ("http", HTTP),
54    ("io", IO),
55    ("json", JSON),
56    ("log", LOG),
57    ("net", NET),
58    ("process", PROCESS),
59    ("strings", STRINGS),
60    ("sync", SYNC),
61    ("task", TASK),
62    ("test", TEST),
63    ("time", TIME),
64];
65
66#[cfg(test)]
67mod tests {
68    use std::collections::BTreeSet;
69    use std::path::Path;
70
71    /// Every `std/*/lib.nova` on disk is embedded, and nothing else is.
72    #[test]
73    fn every_std_module_is_embedded() {
74        let root = Path::new(env!("CARGO_MANIFEST_DIR"));
75        let on_disk: BTreeSet<String> = std::fs::read_dir(root)
76            .expect("read std/")
77            .map(|entry| entry.expect("read an entry of std/").path())
78            .filter(|path| path.join("lib.nova").is_file())
79            .map(|path| {
80                path.file_name()
81                    .expect("a directory name")
82                    .to_string_lossy()
83                    .into_owned()
84            })
85            .collect();
86        let embedded: BTreeSet<String> = super::ALL
87            .iter()
88            .map(|(name, _)| name.to_string())
89            .collect();
90        assert_eq!(embedded, on_disk);
91        assert_eq!(on_disk.len(), 17);
92    }
93
94    /// Each entry carries its own file, not a neighbour's.
95    #[test]
96    fn each_entry_is_its_own_file() {
97        let root = Path::new(env!("CARGO_MANIFEST_DIR"));
98        for (name, source) in super::ALL {
99            let on_disk = std::fs::read_to_string(root.join(name).join("lib.nova"))
100                .expect("read a std module");
101            assert_eq!(source, on_disk, "std/{name}/lib.nova");
102        }
103    }
104}