1#![doc = include_str!("../README.md")]
2
3use std::ffi::OsString;
4use std::process::Stdio;
5use std::time::Duration;
6
7use crossbeam::channel::Receiver;
8use thiserror::Error;
9
10use crate::errors::CmdError;
11
12pub mod debug;
13pub mod errors;
14mod impls;
15pub mod prelude;
16mod test;
17
18pub type Result<T> = std::result::Result<T, Error>;
19
20#[derive(Error, Debug)]
21pub enum Error {
22 #[error("cmd error: {0}")]
23 CommandError(#[from] CmdError),
24
25 #[error(transparent)]
26 IoError(#[from] std::io::Error),
27}
28
29#[derive(Debug)]
30pub struct Cmd {
31 pub(crate) debug: bool,
32 pub(crate) program: OsString,
33 pub(crate) args: Vec<OsString>,
34 pub(crate) cwd: Option<OsString>,
35 pub(crate) stdin: Option<Stdio>,
36 pub(crate) stdout: Option<Stdio>,
37 pub(crate) stderr: Option<Stdio>,
38 pub(crate) timeout: Option<Duration>,
39 pub(crate) signal: Option<Receiver<()>>,
40}
41
42#[derive(Debug)]
43pub struct CommandBuilder {
44 pub(crate) debug: bool,
45 pub(crate) program: OsString,
46 pub(crate) cwd: Option<OsString>,
47 pub(crate) args: Vec<OsString>,
48 pub(crate) stdin: Option<Stdio>,
49 pub(crate) stdout: Option<Stdio>,
50 pub(crate) stderr: Option<Stdio>,
51 pub(crate) timeout: Option<Duration>,
52 pub(crate) signal: Option<Receiver<()>>,
53}
54
55pub(crate) trait OutputResult {
56 fn to_result(&self) -> Result<Vec<u8>>;
57 fn try_to_result(&self) -> Result<Vec<u8>>;
58}
59
60pub trait Vec8ToString {
61 fn as_str(&self) -> Option<&str>;
62}