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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! File I/O operations for USLM documents
//!
//! This module provides functions for reading and writing files,
//! including XML loading and JSON serialization.
use ;
use ;
use ;
use crateParseError;
type Result<T> = Result;
/// Load an XML file from disk into a string
///
/// # Arguments
///
/// * `path` - Path to the XML file to load
///
/// # Returns
///
/// The file contents as a `String`, or an I/O error if the file cannot be read.
///
/// # Examples
///
/// ```
/// use words_to_data::io::load_xml_file;
///
/// let content = load_xml_file("tests/test_data/usc/2025-07-18/usc07.xml").unwrap();
/// assert!(content.contains("uscDoc"));
/// ```
/// Write any serializable data to a JSON file with pretty formatting
///
/// # Arguments
///
/// * `data` - The data to serialize (must implement `Serialize`)
/// * `json_path` - Path where the JSON file will be written
///
/// # Returns
///
/// `Ok(())` if successful, or a `ParseError` if serialization or file writing fails.
///
/// # Examples
///
/// ```no_run
/// use words_to_data::io::write_json_file;
///
/// let data = vec!["hello", "world"];
/// write_json_file(&data, "output.json").unwrap();
/// ```
/// Read and deserialize a JSON file into any type
///
/// # Arguments
///
/// * `json_path` - Path to the JSON file to read
///
/// # Returns
///
/// The deserialized data of type `T`, or a `ParseError` if reading or
/// deserialization fails.
///
/// # Examples
///
/// ```no_run
/// use words_to_data::io::read_json_file;
///
/// let data: Vec<String> = read_json_file("data.json").unwrap();
/// ```