astrograph/output/
mod.rs

1use std::{
2    fmt::Debug,
3    path::{Path, PathBuf},
4};
5
6use dyn_clone::DynClone;
7
8use crate::LocalObservation;
9
10/// An output for SVG files
11pub mod svg;
12
13pub mod logger;
14
15/// The trait for structs that output to a file. It may be made more general in future to better
16/// accommodate non-file outputs e.g. console loggers, or outputs to screen or streams
17pub trait Output: DynClone + Debug + Sync {
18    /// # Errors
19    /// implementations may panic if there is an error in the filesystem e.g. writing is not
20    /// allowed for a user in a specific directory, or one or more of the directories are files
21    /// that have already been created
22    fn write_observations(
23        &self,
24        observations: &[LocalObservation],
25        observatory_name: &str,
26        time: i128,
27        output_path_root: &Path,
28    ) -> Result<(), std::io::Error>;
29
30    /// # Errors
31    /// implementations may panif if there is an error in the filesystem e.g. the user is missing
32    /// permissions, a directory in the path is a file.
33    fn flush(&self) -> Result<(), std::io::Error> {
34        Ok(())
35    }
36}
37dyn_clone::clone_trait_object!(Output);
38
39#[must_use]
40pub fn to_default_path(
41    output_path_root: &Path,
42    observatory_name: &str,
43    time: i128,
44    extension: &str,
45) -> PathBuf {
46    let mut path = output_path_root.to_owned();
47    path.push(observatory_name);
48    path.push(format!("{time:010}{extension}"));
49
50    path
51}
52
53#[cfg(test)]
54mod tests {}