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
40 pub fn eof() -> IoError {
42 kind: old_io::EndOfFile,
48 pub fn timeout(desc: &'static str) -> IoError {
50 kind: old_io::TimedOut,
56 pub fn short_write(n: uint, desc: &'static str) -> IoError {
58 kind: if n == 0 { old_io::TimedOut } else { old_io::ShortWrite(n) },
64 pub fn unimpl() -> IoError {
66 kind: old_io::IoUnavailable,
67 desc: "operations not yet supported",
72 // unix has nonzero values as errors
73 pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
74 if ret != Int::zero() {
81 pub fn keep_going<F>(data: &[u8], mut f: F) -> i64 where
82 F: FnMut(*const u8, uint) -> i64,
84 let origamt = data.len();
85 let mut data = data.as_ptr();
86 let mut amt = origamt;
88 let ret = retry(|| f(data, amt));
93 data = unsafe { data.offset(ret as int) };
98 return (origamt - amt) as i64;
101 /// A trait for viewing representations from std types
103 pub trait AsInner<Inner: ?Sized> {
104 fn as_inner(&self) -> &Inner;
107 /// A trait for viewing representations from std types
109 pub trait AsInnerMut<Inner: ?Sized> {
110 fn as_inner_mut(&mut self) -> &mut Inner;
113 /// A trait for extracting representations from std types
115 pub trait IntoInner<Inner> {
116 fn into_inner(self) -> Inner;
119 /// A trait for creating std types from internal representations
121 pub trait FromInner<Inner> {
122 fn from_inner(inner: Inner) -> Self;
127 pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
128 fn program(&self) -> &CString;
129 fn args(&self) -> &[CString];
130 fn env(&self) -> Option<&collections::HashMap<K, V>>;
131 fn cwd(&self) -> Option<&CString>;
132 fn uid(&self) -> Option<uint>;
133 fn gid(&self) -> Option<uint>;
134 fn detach(&self) -> bool;