Skip to main content

tyt_material/
dependencies_impl.rs

1use crate::{Dependencies, Error, Result};
2use std::{
3    ffi::OsStr,
4    fs,
5    path::{Path, PathBuf},
6};
7
8#[derive(Clone, Copy, Debug, Default)]
9pub struct DependenciesImpl;
10
11impl Dependencies for DependenciesImpl {
12    fn copy_file<P1: AsRef<Path>, P2: AsRef<Path>>(&self, from: P1, to: P2) -> Result<()> {
13        fs::copy(from.as_ref(), to.as_ref())?;
14        Ok(())
15    }
16
17    fn create_temp_dir(&self) -> Result<PathBuf> {
18        Ok(tyt_injection::create_temp_dir()?)
19    }
20
21    fn exec_magick<I, S>(&self, args: I) -> Result<Vec<u8>>
22    where
23        I: IntoIterator<Item = S>,
24        S: AsRef<OsStr>,
25    {
26        tyt_injection::exec_map("magick", args, Error::IO, Error::Magick)
27    }
28
29    fn glob_single_match(&self, pattern: &str) -> Result<PathBuf> {
30        tyt_injection::glob_single_match(pattern).map_err(|e| Error::Glob(format!("{e}")))
31    }
32
33    fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()> {
34        Ok(tyt_injection::remove_dir_all(path.as_ref())?)
35    }
36
37    fn write_stdout(&self, contents: &[u8]) -> Result<()> {
38        Ok(tyt_injection::write_stdout(contents)?)
39    }
40}