use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct RerunConfig {
pub application_id: String,
pub recording_id: Option<String>,
pub spawn_viewer: bool,
pub connect_addr: Option<String>,
pub save_path: Option<String>,
pub record_to_path: Option<PathBuf>,
pub default_timeline: String,
}
impl Default for RerunConfig {
fn default() -> Self {
Self {
application_id: "burn-training".to_string(),
recording_id: None,
spawn_viewer: true,
connect_addr: None,
save_path: None,
record_to_path: None,
default_timeline: "epoch".to_string(),
}
}
}
impl RerunConfig {
pub fn new(application_id: impl Into<String>) -> Self {
Self {
application_id: application_id.into(),
..Default::default()
}
}
pub fn with_recording_id(mut self, recording_id: impl Into<String>) -> Self {
self.recording_id = Some(recording_id.into());
self
}
pub fn with_spawn_viewer(mut self, spawn: bool) -> Self {
self.spawn_viewer = spawn;
self
}
pub fn with_connect_addr(mut self, addr: impl Into<String>) -> Self {
self.connect_addr = Some(addr.into());
self
}
pub fn with_save_path(mut self, path: impl Into<String>) -> Self {
self.save_path = Some(path.into());
self
}
pub fn with_record_to_path(mut self, path: impl Into<PathBuf>) -> Self {
self.record_to_path = Some(path.into());
self
}
pub fn with_default_timeline(mut self, timeline: impl Into<String>) -> Self {
self.default_timeline = timeline.into();
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = RerunConfig::default();
assert_eq!(config.application_id, "burn-training");
assert!(config.spawn_viewer);
assert_eq!(config.default_timeline, "epoch");
}
#[test]
fn test_builder_pattern() {
let config = RerunConfig::new("test-app")
.with_recording_id("test-recording")
.with_spawn_viewer(false)
.with_connect_addr("127.0.0.1:9876")
.with_save_path("/tmp/recording.rrd")
.with_default_timeline("iteration")
.with_record_to_path("mirror.rrd");
assert_eq!(config.application_id, "test-app");
assert_eq!(config.recording_id, Some("test-recording".to_string()));
assert!(!config.spawn_viewer);
assert_eq!(config.connect_addr, Some("127.0.0.1:9876".to_string()));
assert_eq!(config.save_path, Some("/tmp/recording.rrd".to_string()));
assert_eq!(config.default_timeline, "iteration");
assert_eq!(config.record_to_path, Some(PathBuf::from("mirror.rrd")));
}
}