1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#![doc(html_root_url = "https://docs.rs/conch-runtime/0.1")]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(all(not(test), feature = "clippy"), deny(print_stdout))]
#![cfg_attr(feature = "clippy", deny(wrong_self_convention))]
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]
#![deny(missing_docs)]
#![deny(trivial_casts)]
#![deny(unused_import_braces)]
#![deny(unused_qualifications)]
#![cfg_attr(windows, feature(unique))]
#[cfg(unix)] extern crate libc;
#[cfg(windows)] extern crate kernel32;
#[cfg(windows)] extern crate winapi;
#[cfg(feature = "conch-parser")]
extern crate conch_parser;
#[macro_use] extern crate futures;
extern crate futures_cpupool;
extern crate glob;
#[macro_use] extern crate lazy_static;
extern crate mio;
#[macro_use] extern crate rental;
extern crate tokio_core;
extern crate tokio_io;
extern crate tokio_process;
extern crate void;
#[macro_use]
pub mod error;
pub mod env;
pub mod eval;
pub mod future;
pub mod io;
pub mod os;
pub mod spawn;
mod future_ext;
mod ref_counted;
#[cfg(unix)]
#[path="sys/unix/mod.rs"]
mod sys;
#[cfg(windows)]
#[path="sys/windows/mod.rs"]
mod sys;
pub use self::ref_counted::RefCounted;
pub use self::spawn::Spawn;
const POLLED_TWICE: &'static str = "this future cannot be polled again after completion!";
const CANCELLED_TWICE: &'static str = "this future cannot be cancelled again after completion!";
const IFS_DEFAULT: &'static str = " \t\n";
pub const EXIT_SUCCESS: ExitStatus = ExitStatus::Code(0);
pub const EXIT_ERROR: ExitStatus = ExitStatus::Code(1);
pub const EXIT_CMD_NOT_EXECUTABLE: ExitStatus = ExitStatus::Code(126);
pub const EXIT_CMD_NOT_FOUND: ExitStatus = ExitStatus::Code(127);
pub const STDIN_FILENO: Fd = 0;
pub const STDOUT_FILENO: Fd = 1;
pub const STDERR_FILENO: Fd = 2;
pub type Fd = u16;
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum ExitStatus {
Code(i32),
Signal(i32),
}
impl ExitStatus {
pub fn success(&self) -> bool {
*self == EXIT_SUCCESS
}
}
impl ::std::fmt::Display for ExitStatus {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
ExitStatus::Code(code) => write!(f, "exit code: {}", code),
ExitStatus::Signal(code) => write!(f, "signal: {}", code),
}
}
}
impl From<::std::process::ExitStatus> for ExitStatus {
fn from(exit: ::std::process::ExitStatus) -> ExitStatus {
#[cfg(unix)]
fn get_signal(exit: ::std::process::ExitStatus) -> Option<i32> {
::std::os::unix::process::ExitStatusExt::signal(&exit)
}
#[cfg(windows)]
fn get_signal(_exit: ::std::process::ExitStatus) -> Option<i32> { None }
match exit.code() {
Some(code) => ExitStatus::Code(code),
None => get_signal(exit).map_or(EXIT_ERROR, ExitStatus::Signal),
}
}
}
trait IntoInner: Sized {
type Inner;
fn inner(&self) -> &Self::Inner;
fn into_inner(self) -> Self::Inner;
fn from_inner(inner: Self::Inner) -> Self;
}