pub struct FileObserver { /* private fields */ }Expand description
Reads a single JSON (or plain-text) file on each observe call.
Implementations§
Source§impl FileObserver
impl FileObserver
Sourcepub fn new(path: impl AsRef<Path>) -> Self
pub fn new(path: impl AsRef<Path>) -> Self
Examples found in repository?
examples/custom_adapters.rs (line 27)
12fn main() -> Result<()> {
13 // Prepare a tiny status file the FileObserver will read.
14 let status_path = PathBuf::from("/tmp/omega-status-example.json");
15 {
16 let mut f = std::fs::File::create(&status_path).expect("create status file");
17 writeln!(
18 f,
19 r#"{{"signal": "external", "load": 0.42, "note": "hello from file"}}"#
20 )
21 .expect("write status");
22 }
23
24 let log_path = PathBuf::from("/tmp/omega-actions.log");
25 let _ = std::fs::remove_file(&log_path);
26
27 let observer = FileObserver::new(&status_path);
28 let executor = LoggingExecutor::new([
29 "noop".into(),
30 "observe".into(),
31 "explore".into(),
32 "exploit".into(),
33 "stabilize".into(),
34 ])
35 .with_log_file(&log_path)
36 .echo_stdout(true);
37
38 let mut kernel = Kernel::with_adapters(observer, executor);
39 kernel.autosave = false;
40 kernel.auto_checkpoint_on_patch = false;
41
42 let report = kernel.run("adapt to external file signal", 5)?;
43 println!(
44 "\nReport: steps={} err {:.3} → {:.3} decreased={} actions={:?}",
45 report.steps,
46 report.early_avg_err,
47 report.final_avg_err,
48 report.error_decreased,
49 report.last_actions
50 );
51
52 println!("\nAction log written to {}", log_path.display());
53 if let Ok(log) = std::fs::read_to_string(&log_path) {
54 println!("{log}");
55 }
56
57 Ok(())
58}Trait Implementations§
Source§impl Observer for FileObserver
Available on crate feature std only.
impl Observer for FileObserver
Available on crate feature
std only.Auto Trait Implementations§
impl Forget for FileObserver
impl Freeze for FileObserver
impl Move for FileObserver
impl RefUnwindSafe for FileObserver
impl Send for FileObserver
impl Sync for FileObserver
impl Unpin for FileObserver
impl UnsafeUnpin for FileObserver
impl UnwindSafe for FileObserver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more