INNER CODE UNIT · Rust
save_to_file
tangle-network/blueprint · crates/blueprint-profiling/src/lib.rs:112
pub fn save_to_file(&self, path: impl AsRef<std::path::Path>) -> Result<(), ProfilingError> {
let json = serde_json::to_string_pretty(self).map_err(|e| {
ProfilingError::InvalidConfiguration(format!("JSON serialization failed: {e}"))
})?;
std::fs::write(path.as_ref(), json).map_err(|e| {
ProfilingError::InvalidConfiguration(format!("Failed to write file: {e}"))
})?;
Ok(())
}
/// Load profiles from a JSON file
pub fn load_from_file(path: impl AsRef<std::path::Path>) -> Result<Self, ProfilingError> {
let content = std::fs::read_to_string(path.as_ref()).map_err(|e| {
ProfilingError::InvalidConfiguration(format!("Failed to read file: {e}"))
})?;