mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-06 15:07:36 +00:00

This commit removes all the old casting/generic traits from `std::num` that are no longer in use by the standard library. This additionally removes the old `strconv` module which has not seen much use in quite a long time. All generic functionality has been supplanted with traits in the `num` crate and the `strconv` module is supplanted with the [rust-strconv crate][rust-strconv]. [rust-strconv]: https://github.com/lifthrasiir/rust-strconv This is a breaking change due to the removal of these deprecated crates, and the alternative crates are listed above. [breaking-change]
94 lines
2.6 KiB
Rust
94 lines
2.6 KiB
Rust
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
#![allow(missing_docs)]
|
|
#![allow(non_camel_case_types)]
|
|
|
|
use prelude::v1::*;
|
|
|
|
use io::{self, ErrorKind};
|
|
use libc;
|
|
use num::One;
|
|
use ops::Neg;
|
|
|
|
pub mod backtrace;
|
|
pub mod c;
|
|
pub mod condvar;
|
|
pub mod ext;
|
|
pub mod fd;
|
|
pub mod fs2;
|
|
pub mod mutex;
|
|
pub mod net;
|
|
pub mod os;
|
|
pub mod os_str;
|
|
pub mod pipe2;
|
|
pub mod process2;
|
|
pub mod rwlock;
|
|
pub mod stack_overflow;
|
|
pub mod sync;
|
|
pub mod thread;
|
|
pub mod thread_local;
|
|
pub mod time;
|
|
pub mod stdio;
|
|
|
|
pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
|
match errno as libc::c_int {
|
|
libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
|
|
libc::ECONNRESET => ErrorKind::ConnectionReset,
|
|
libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
|
|
libc::EPIPE => ErrorKind::BrokenPipe,
|
|
libc::ENOTCONN => ErrorKind::NotConnected,
|
|
libc::ECONNABORTED => ErrorKind::ConnectionAborted,
|
|
libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
|
|
libc::EADDRINUSE => ErrorKind::AddrInUse,
|
|
libc::ENOENT => ErrorKind::NotFound,
|
|
libc::EINTR => ErrorKind::Interrupted,
|
|
libc::EINVAL => ErrorKind::InvalidInput,
|
|
libc::ETIMEDOUT => ErrorKind::TimedOut,
|
|
libc::consts::os::posix88::EEXIST => ErrorKind::AlreadyExists,
|
|
|
|
// These two constants can have the same value on some systems,
|
|
// but different values on others, so we can't use a match
|
|
// clause
|
|
x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
|
|
ErrorKind::WouldBlock,
|
|
|
|
_ => ErrorKind::Other,
|
|
}
|
|
}
|
|
|
|
pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> {
|
|
let one: T = T::one();
|
|
if t == -one {
|
|
Err(io::Error::last_os_error())
|
|
} else {
|
|
Ok(t)
|
|
}
|
|
}
|
|
|
|
#[allow(deprecated)]
|
|
pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
|
|
where T: One + PartialEq + Neg<Output=T>, F: FnMut() -> T
|
|
{
|
|
loop {
|
|
match cvt(f()) {
|
|
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
|
other => return other,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn ms_to_timeval(ms: u64) -> libc::timeval {
|
|
libc::timeval {
|
|
tv_sec: (ms / 1000) as libc::time_t,
|
|
tv_usec: ((ms % 1000) * 1000) as libc::suseconds_t,
|
|
}
|
|
}
|