Skip to main content

asimov_env/
env.rs

1// This is free and unencumbered software released into the public domain.
2
3#[cfg(feature = "std")]
4use std::{io::Result, process::ExitStatus};
5
6#[cfg(not(feature = "std"))]
7type Result<T> = core::result::Result<T, Box<dyn core::error::Error>>;
8
9pub trait Env {
10    fn is_module_available(&self, module_name: impl ToString) -> Result<bool> {
11        Ok(self.available_modules()?.contains(&module_name.to_string()))
12    }
13
14    fn is_module_installed(&self, module_name: impl ToString) -> Result<bool> {
15        if !self.is_initialized() {
16            return Ok(false);
17        }
18        Ok(self.installed_modules()?.contains(&module_name.to_string()))
19    }
20
21    fn is_module_enabled(&self, _module_name: impl ToString) -> Result<bool> {
22        Ok(true) // TODO
23    }
24
25    #[cfg(feature = "std")]
26    fn path(&self) -> Option<&std::path::PathBuf> {
27        None
28    }
29
30    fn is_initialized(&self) -> bool {
31        false
32    }
33
34    fn initialize(&self) -> Result<()> {
35        Ok(())
36    }
37
38    fn available_modules(&self) -> std::io::Result<Vec<String>> {
39        Ok(vec![])
40    }
41
42    fn installed_modules(&self) -> std::io::Result<Vec<String>> {
43        Ok(vec![])
44    }
45
46    #[cfg(feature = "std")]
47    fn install_module(
48        &self,
49        _module_name: impl ToString,
50        _verbosity: Option<u8>,
51    ) -> Result<ExitStatus> {
52        Ok(ExitStatus::default())
53    }
54
55    #[cfg(feature = "std")]
56    fn uninstall_module(
57        &self,
58        _module_name: impl ToString,
59        _verbosity: Option<u8>,
60    ) -> Result<ExitStatus> {
61        Ok(ExitStatus::default())
62    }
63}