use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Config {
pub file_name: String,
pub backend: String,
pub algorithm: String,
pub filter_name: String,
pub rotation_axis: Option<f32>,
pub remove_stripe_method: String,
pub retrieve_phase_method: String,
pub num_iter: usize,
pub nsino_per_chunk: usize,
pub save_format: String,
}
impl Default for Config {
fn default() -> Self {
Config {
file_name: String::new(),
backend: "auto".into(),
algorithm: "fbp".into(),
filter_name: "ramp".into(),
rotation_axis: None,
remove_stripe_method: "none".into(),
retrieve_phase_method: "none".into(),
num_iter: 1,
nsino_per_chunk: 8,
save_format: "tiff".into(),
}
}
}
impl Config {
pub fn to_toml(&self) -> anyhow::Result<String> {
Ok(toml::to_string_pretty(self)?)
}
pub fn write(&self, path: &Path) -> anyhow::Result<()> {
std::fs::write(path, self.to_toml()?)?;
Ok(())
}
pub fn load(path: &Path) -> anyhow::Result<Self> {
let text = std::fs::read_to_string(path)?;
Ok(toml::from_str(&text)?)
}
}