1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(missing_docs)]
13 use old_io::{self, IoError, IoResult};
15 use sys::{last_error, retry};
20 use old_path::BytesContainer;
24 #[macro_use] pub mod helper_thread;
38 // common error constructors
41 pub fn eof() -> IoError {
43 kind: old_io::EndOfFile,
50 pub fn timeout(desc: &'static str) -> IoError {
52 kind: old_io::TimedOut,
59 pub fn short_write(n: uint, desc: &'static str) -> IoError {
61 kind: if n == 0 { old_io::TimedOut } else { old_io::ShortWrite(n) },
68 pub fn unimpl() -> IoError {
70 kind: old_io::IoUnavailable,
71 desc: "operations not yet supported",
76 // unix has nonzero values as errors
78 pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
79 if ret != Int::zero() {
86 pub fn keep_going<F>(data: &[u8], mut f: F) -> i64 where
87 F: FnMut(*const u8, uint) -> i64,
89 let origamt = data.len();
90 let mut data = data.as_ptr();
91 let mut amt = origamt;
93 let ret = retry(|| f(data, amt));
98 data = unsafe { data.offset(ret as int) };
103 return (origamt - amt) as i64;
106 /// A trait for viewing representations from std types
108 pub trait AsInner<Inner: ?Sized> {
109 fn as_inner(&self) -> &Inner;
112 /// A trait for viewing representations from std types
114 pub trait AsInnerMut<Inner: ?Sized> {
115 fn as_inner_mut(&mut self) -> &mut Inner;
118 /// A trait for extracting representations from std types
120 pub trait IntoInner<Inner> {
121 fn into_inner(self) -> Inner;
124 /// A trait for creating std types from internal representations
126 pub trait FromInner<Inner> {
127 fn from_inner(inner: Inner) -> Self;
132 pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
133 fn program(&self) -> &CString;
134 fn args(&self) -> &[CString];
135 fn env(&self) -> Option<&collections::HashMap<K, V>>;
136 fn cwd(&self) -> Option<&CString>;
137 fn uid(&self) -> Option<uint>;
138 fn gid(&self) -> Option<uint>;
139 fn detach(&self) -> bool;