1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 Vallés Puig, Ramon
//! VSOP87 **output stage**
//!
//! `io.rs` is responsible only for **side‑effects**: taking the Rust source
//! blobs produced by [`codegen`](crate::scripts::vsop87::codegen) and writing
//! one file per VSOP87 version (`vsop87a.rs`, `vsop87e.rs`, …) inside the
//! directory pointed at by Cargo’s `OUT_DIR` environment variable.
//!
//! Why a separate module?
//! * Keeps pure/functional stages (`collect`, `codegen`) free of I/O.
//! * Makes it easy to swap the backend later (e.g. in‑memory, mock FS, etc.).
//!
//! The function exposed here is minimal: it receives the map returned by
//! `codegen::generate_modules` and the already‑resolved `out_dir` path; it
//! performs the write and surfaces any error through `anyhow`.
use ;
use Context;
/// Persist each `(version → source_code)` pair into an actual `.rs` file.
///
/// * `mods` – map keyed by the **version letter** (A, E, …) produced by
/// `codegen`.
/// * `out_dir` – directory where Cargo expects build scripts to drop their
/// generated artefacts. Usually passed from the caller as
/// `PathBuf::from(env!("OUT_DIR"))`.
///
/// For every `(version, code)` entry we create a file named
/// `vsop87{version}.rs`, lowering the version letter for consistency, e.g.:
///
/// ```text
/// vsop87a.rs // ← version 'A'
/// vsop87e.rs // ← version 'E'
/// ```
///
/// The function is **idempotent**: it always overwrites the file with the new
/// contents. Errors from the file system are wrapped with context so that the
/// caller knows *which* file failed.