refactor(study): move export_json() from persistence to export module

This commit is contained in:
Manuel Raimann
2026-02-12 15:42:34 +01:00
parent a502d7e1b8
commit f0798ca58a
2 changed files with 17 additions and 14 deletions
+17
View File
@@ -220,6 +220,23 @@ where
}
}
#[cfg(feature = "serde")]
impl<V: PartialOrd + Clone + serde::Serialize> Study<V> {
/// Export trials as a pretty-printed JSON array to a file.
///
/// Each element in the array is a serialized [`CompletedTrial`].
/// Requires the `serde` feature.
///
/// # Errors
///
/// Returns an I/O error if the file cannot be created or written.
pub fn export_json(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
let file = std::fs::File::create(path)?;
let trials = self.trials();
serde_json::to_writer_pretty(file, &trials).map_err(std::io::Error::other)
}
}
impl Study<f64> {
/// Generate an HTML report with interactive Plotly.js charts.
///
-14
View File
@@ -41,20 +41,6 @@ pub struct StudySnapshot<V> {
#[cfg(feature = "serde")]
impl<V: PartialOrd + Clone + serde::Serialize> Study<V> {
/// Export trials as a pretty-printed JSON array to a file.
///
/// Each element in the array is a serialized [`CompletedTrial`].
/// Requires the `serde` feature.
///
/// # Errors
///
/// Returns an I/O error if the file cannot be created or written.
pub fn export_json(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
let file = std::fs::File::create(path)?;
let trials = self.trials();
serde_json::to_writer_pretty(file, &trials).map_err(std::io::Error::other)
}
/// Save the study state to a JSON file.
///
/// # Errors