]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/common/mod.rs
Fallout of std::old_io deprecation
[rust.git] / src / libstd / sys / common / mod.rs
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.
4 //
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.
10
11 #![allow(missing_docs)]
12
13 use old_io::{self, IoError, IoResult};
14 use prelude::v1::*;
15 use sys::{last_error, retry};
16 use ffi::CString;
17 use num::Int;
18
19 #[allow(deprecated)]
20 use old_path::BytesContainer;
21
22 use collections;
23
24 #[macro_use] pub mod helper_thread;
25
26 pub mod backtrace;
27 pub mod condvar;
28 pub mod mutex;
29 pub mod net;
30 pub mod net2;
31 pub mod rwlock;
32 pub mod stack;
33 pub mod thread;
34 pub mod thread_info;
35 pub mod thread_local;
36 pub mod wtf8;
37
38 // common error constructors
39
40 #[allow(deprecated)]
41 pub fn eof() -> IoError {
42     IoError {
43         kind: old_io::EndOfFile,
44         desc: "end of file",
45         detail: None,
46     }
47 }
48
49 #[allow(deprecated)]
50 pub fn timeout(desc: &'static str) -> IoError {
51     IoError {
52         kind: old_io::TimedOut,
53         desc: desc,
54         detail: None,
55     }
56 }
57
58 #[allow(deprecated)]
59 pub fn short_write(n: uint, desc: &'static str) -> IoError {
60     IoError {
61         kind: if n == 0 { old_io::TimedOut } else { old_io::ShortWrite(n) },
62         desc: desc,
63         detail: None,
64     }
65 }
66
67 #[allow(deprecated)]
68 pub fn unimpl() -> IoError {
69     IoError {
70         kind: old_io::IoUnavailable,
71         desc: "operations not yet supported",
72         detail: None,
73     }
74 }
75
76 // unix has nonzero values as errors
77 #[allow(deprecated)]
78 pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
79     if ret != Int::zero() {
80         Err(last_error())
81     } else {
82         Ok(())
83     }
84 }
85
86 pub fn keep_going<F>(data: &[u8], mut f: F) -> i64 where
87     F: FnMut(*const u8, uint) -> i64,
88 {
89     let origamt = data.len();
90     let mut data = data.as_ptr();
91     let mut amt = origamt;
92     while amt > 0 {
93         let ret = retry(|| f(data, amt));
94         if ret == 0 {
95             break
96         } else if ret != -1 {
97             amt -= ret as uint;
98             data = unsafe { data.offset(ret as int) };
99         } else {
100             return ret;
101         }
102     }
103     return (origamt - amt) as i64;
104 }
105
106 /// A trait for viewing representations from std types
107 #[doc(hidden)]
108 pub trait AsInner<Inner: ?Sized> {
109     fn as_inner(&self) -> &Inner;
110 }
111
112 /// A trait for viewing representations from std types
113 #[doc(hidden)]
114 pub trait AsInnerMut<Inner: ?Sized> {
115     fn as_inner_mut(&mut self) -> &mut Inner;
116 }
117
118 /// A trait for extracting representations from std types
119 #[doc(hidden)]
120 pub trait IntoInner<Inner> {
121     fn into_inner(self) -> Inner;
122 }
123
124 /// A trait for creating std types from internal representations
125 #[doc(hidden)]
126 pub trait FromInner<Inner> {
127     fn from_inner(inner: Inner) -> Self;
128 }
129
130 #[doc(hidden)]
131 #[allow(deprecated)]
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;
140 }