conch_runtime_pshaw/
lib.rs

1//! A library for executing programs written in the shell programming language.
2//!
3//! This library offers executing already parsed shell commands as defined by the
4//! [POSIX.1-2008][POSIX] standard. This runtime attempts to remain agnostic to the
5//! specific Abstract Syntax Tree format a parser could produce, as well as agnostic
6//! to features supported by the OS to be as cross platform as possible.
7//!
8//! Specifically implementations are provided for all the default AST nodes produced
9//! by the [`conch-parser`] crate. Unlike other Unix shells, this
10//! library supports Windows<sup>1</sup> and can likely be extended for other
11//! operating systems as well.
12//!
13//! <sup>1</sup>Major features are reasonably supported in Windows to the extent
14//! possible. Due to OS differences (e.g. async I/O models) and inherent implementation
15//! exepectations of the shell programming language, certain features may require
16//! additional runtime costs, or may be limited in nature (e.g. inheriting arbitrary
17//! numbered file descriptors [other than stdio] is difficult/impossible due to the
18//! way Windows addresses file handles).
19//!
20//! [POSIX]: http://pubs.opengroup.org/onlinepubs/9699919799/
21//! [`conch-parser`]: https://docs.rs/conch-parser
22//!
23//! # Supported Cargo Features
24//!
25//! * `conch-parser`: enable implementations on the default AST types provided
26//! by the `conch-parser` crate
27
28#![doc(html_root_url = "https://docs.rs/conch-runtime/0.1")]
29#![cfg_attr(not(test), deny(clippy::print_stdout))]
30#![deny(clippy::wrong_self_convention)]
31#![deny(missing_copy_implementations)]
32#![deny(missing_debug_implementations)]
33#![deny(missing_docs)]
34#![deny(trivial_casts)]
35#![deny(unused_import_braces)]
36#![deny(unused_qualifications)]
37#![deny(rust_2018_idioms)]
38
39pub mod env;
40pub mod error;
41pub mod eval;
42pub mod io;
43pub mod path;
44pub mod spawn;
45
46mod exit_status;
47mod ref_counted;
48
49mod sys {
50    #[cfg(unix)]
51    mod unix;
52    #[cfg(unix)]
53    pub(crate) use self::unix::*;
54
55    #[cfg(windows)]
56    mod windows;
57    #[cfg(windows)]
58    pub(crate) use self::windows::*;
59}
60
61pub use self::exit_status::{
62    ExitStatus, EXIT_CMD_NOT_EXECUTABLE, EXIT_CMD_NOT_FOUND, EXIT_ERROR, EXIT_SUCCESS,
63};
64pub use self::ref_counted::RefCounted;
65pub use self::spawn::Spawn;
66
67/// The default value of `$IFS` unless overriden.
68const IFS_DEFAULT: &str = " \t\n";
69
70/// File descriptor for standard input.
71pub const STDIN_FILENO: Fd = 0;
72/// File descriptor for standard output.
73pub const STDOUT_FILENO: Fd = 1;
74/// File descriptor for standard error.
75pub const STDERR_FILENO: Fd = 2;
76
77lazy_static::lazy_static! {
78    static ref HOME: String = String::from("HOME");
79}
80
81/// The type that represents a file descriptor within shell scripts.
82pub type Fd = u16;
83
84/// A private trait for converting to inner types.
85trait IntoInner: Sized {
86    /// The inner type.
87    type Inner;
88    /// Borrow a reference to the inner type.
89    fn inner(&self) -> &Self::Inner;
90    /// Borrow a mutable reference to the inner type.
91    fn inner_mut(&mut self) -> &mut Self::Inner;
92    /// Take ownership of the inner type.
93    fn into_inner(self) -> Self::Inner;
94    /// Convert an inner value to its wrapper.
95    fn from_inner(inner: Self::Inner) -> Self;
96}