thot-local 0.10.0-intermediate

Local functionality for Thot data management and analysis software.
Documentation
//! Common use functions.
use crate::constants::*;
use crate::result::{Error, Result};
use std::fs;
use std::path::{Path, PathBuf};

/// Canonicalizes a path.
///
/// # Notes
/// Currently delegates to std::fs::canonicalize, but reserved for
/// easy future changes.
pub fn canonicalize_path<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
    match fs::canonicalize(path) {
        Ok(path) => Ok(path),
        Err(err) => Err(Error::from(err)),
    }
}

// ******************
// *** file paths ***
// ******************

/// Returns the path to the Thot directory for a given path.
/// <path>/<THOT_DIR>.
pub fn thot_dir_of(path: &Path) -> PathBuf {
    path.join(THOT_DIR)
}

/// Returns the path to the project file for a given path.
/// thot_dir(path)/<PROJECT_FILE>
pub fn project_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(PROJECT_FILE)
}

/// Returns the path to the project settings file for a given path.
/// thot_dir(path)/<PROJECT_SETTINGS_FILE>
pub fn project_settings_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(PROJECT_SETTINGS_FILE)
}

/// Returns the path to the Container file for a given path.
/// thot_dir(path)/<CONTAINER_FILE>
pub fn container_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(CONTAINER_FILE)
}

/// Returns the path to the Container file for a given path.
/// thot_dir(path)/<CONTAINER_SETTINGS_FILE>
pub fn container_settings_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(CONTAINER_SETTINGS_FILE)
}

/// Returns the path to the Container file for a given path.
/// thot_dir(path)/<ASSETS_FILE>
pub fn assets_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(ASSETS_FILE)
}

/// Returns the path to the Container file for a given path.
/// thot_dir(path)/<SCRIPTS_FILE>
pub fn scripts_file_of(path: &Path) -> PathBuf {
    thot_dir_of(path).join(SCRIPTS_FILE)
}

#[cfg(test)]
#[path = "./common_test.rs"]
mod common_test;