Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Herberg Hovd committed Dec 30, 2023
1 parent 52f5bbc commit 340022b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ use tracing_subscriber::registry::Registry;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

/// Setup logging for the library
///
/// This function sets up logging for the library. It uses the `tracing` crate, and the `tracing-subscriber` crate for formatting.
///
/// The log level is defined in the configuration file, and defaults to `INFO`.
///
/// If `log_out` is specifified in teh configuration file, a log file is created with the specified name.
///
/// Additionally, if the `tui` option is set to `true`, the log messages are also written to the TUI.
///
/// If not, the log messages are written to stdout.
pub fn setup_log(settings: &Settings, ui_tx: UnboundedSender<Comm>) {
// Use the log level defined in configuration file, or default to info
let log_level = settings
Expand Down Expand Up @@ -53,7 +64,7 @@ pub fn setup_log(settings: &Settings, ui_tx: UnboundedSender<Comm>) {
// Define layer for TUI
let tui_writer_closure = move || {
TuiWriter {
ui_tx: ui_tx.clone(), // Ensure this clone is okay with your design (consider the lifetime of _ui_tx)
ui_tx: ui_tx.clone()
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/routines/settings/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::process::exit;
use toml::value::Array;
use toml::{self, Table};

/// Settings used for algorithm execution
///
/// The user can specify the desired settings in a TOML configuration file, see `routines::settings::run` for details.
#[derive(Deserialize, Clone, Debug)]
pub struct Settings {
pub computed: Computed,
Expand All @@ -17,6 +20,12 @@ pub struct Computed {
pub fixed: Single,
}

/// The `Error` struct is used to specify the error model
/// - `value`: the value of the error
/// - `class`: the class of the error, can be either `additive` or `proportional`
/// - `poly`: the polynomial coefficients of the error model
///
/// For more information see `routines::evaluation::sigma`
#[derive(Deserialize, Clone, Debug)]
pub struct Error {
pub value: f64,
Expand Down Expand Up @@ -68,6 +77,7 @@ pub struct Config {
pub log_level: Option<String>,
}

/// Read and parse settings from a TOML configuration file
pub fn read(filename: String) -> Settings {
let contents = match fs::read_to_string(&filename) {
Ok(c) => c,
Expand Down

0 comments on commit 340022b

Please sign in to comment.