From f0798ca58a1baba00f8f96acc4a68b4a1f1a8be9 Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Thu, 12 Feb 2026 15:42:34 +0100 Subject: [PATCH] refactor(study): move export_json() from persistence to export module --- src/study/export.rs | 17 +++++++++++++++++ src/study/persistence.rs | 14 -------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/study/export.rs b/src/study/export.rs index 913ab2b..62c6368 100644 --- a/src/study/export.rs +++ b/src/study/export.rs @@ -220,6 +220,23 @@ where } } +#[cfg(feature = "serde")] +impl Study { + /// 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::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 { /// Generate an HTML report with interactive Plotly.js charts. /// diff --git a/src/study/persistence.rs b/src/study/persistence.rs index 6e6ffc9..c9174d6 100644 --- a/src/study/persistence.rs +++ b/src/study/persistence.rs @@ -41,20 +41,6 @@ pub struct StudySnapshot { #[cfg(feature = "serde")] impl Study { - /// 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::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