turtle-build 0.5.8

Ninja-compatible build system for high-level programming languages
Documentation
use crate::{
    infrastructure::{CommandRunner, Console, Database, FileSystem},
    path_pool::PathPool,
};
use alloc::sync::Arc;
use tokio::sync::Mutex;

/// A context.
pub struct Context {
    command_runner: Box<dyn CommandRunner + Send + Sync>,
    console: Arc<Mutex<dyn Console + Send + Sync>>,
    database: Box<dyn Database + Send + Sync>,
    file_system: Arc<dyn FileSystem + Send + Sync>,
    path_pool: Arc<PathPool>,
}

impl Context {
    /// Creates a context.
    pub fn new(
        command_runner: impl CommandRunner + Send + Sync + 'static,
        console: Arc<Mutex<impl Console + Send + Sync + 'static>>,
        database: impl Database + Send + Sync + 'static,
        file_system: impl FileSystem + Send + Sync + 'static,
        path_pool: Arc<PathPool>,
    ) -> Self {
        Self {
            command_runner: Box::new(command_runner),
            console,
            file_system: Arc::new(file_system),
            database: Box::new(database),
            path_pool,
        }
    }

    /// Returns a command runner.
    pub fn command_runner(&self) -> &(dyn CommandRunner + Send + Sync) {
        &*self.command_runner
    }

    /// Returns a console.
    pub fn console(&self) -> &Mutex<dyn Console + Send + Sync> {
        &self.console
    }

    /// Returns a database.
    pub fn database(&self) -> &(dyn Database + Send + Sync) {
        &*self.database
    }

    /// Returns a file system.
    pub fn file_system(&self) -> &Arc<dyn FileSystem + Send + Sync> {
        &self.file_system
    }

    /// Returns a path pool.
    pub fn path_pool(&self) -> &PathPool {
        &self.path_pool
    }
}