Skip to content

Commit 44885b2

Browse files
committed
Use namespaced enum variants.
As per this pull request rust-lang/rust#18973, enum variants require fully qualified path to access them. This commit introduces boring changes to make nix-rust compiles againts new rust.
1 parent 768824d commit 44885b2

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

src/errno.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::num::from_uint;
44
use libc::c_int;
55

66
pub use self::consts::*;
7+
pub use self::consts::Errno::*;
78

89
pub type SysResult<T> = Result<T, SysError>;
910

@@ -672,9 +673,9 @@ mod consts {
672673
EQFULL = 106,
673674
}
674675

675-
pub const ELAST: Errno = EQFULL;
676-
pub const EWOULDBLOCK: Errno = EAGAIN;
677-
pub const EDEADLOCK: Errno = EDEADLK;
676+
pub const ELAST: Errno = Errno::EQFULL;
677+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
678+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
678679

679-
pub const EL2NSYNC: Errno = UnknownErrno;
680+
pub const EL2NSYNC: Errno = Errno::UnknownErrno;
680681
}

src/fcntl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub enum FcntlArg<'a> {
100100

101101
// TODO: Figure out how to handle value fcntl returns
102102
pub fn fcntl(fd: Fd, arg: FcntlArg) -> SysResult<()> {
103+
use self::FcntlArg::*;
104+
103105
let res = unsafe {
104106
match arg {
105107
F_SETFD(flag) => ffi::fcntl(fd, ffi::F_SETFD, flag.bits()),

src/sys/socket.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{mem, ptr, fmt};
2-
use std::num::Int;
32
use libc::{c_void, c_int, socklen_t, size_t, ssize_t};
4-
use fcntl::{Fd, fcntl, F_SETFL, F_SETFD, FD_CLOEXEC, O_NONBLOCK};
3+
use fcntl::{Fd, fcntl, FD_CLOEXEC, O_NONBLOCK};
4+
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
55
use errno::{SysResult, SysError, from_ffi};
66
use features;
77

@@ -257,6 +257,8 @@ pub fn listen(sockfd: Fd, backlog: uint) -> SysResult<()> {
257257
}
258258

259259
pub fn bind(sockfd: Fd, addr: &SockAddr) -> SysResult<()> {
260+
use self::SockAddr::*;
261+
260262
let res = unsafe {
261263
match *addr {
262264
SockIpV4(ref addr) => ffi::bind(sockfd, mem::transmute(addr), mem::size_of::<sockaddr_in>() as socklen_t),
@@ -330,6 +332,8 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> SysResult<Fd> {
330332
}
331333

332334
pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> {
335+
use self::SockAddr::*;
336+
333337
let res = unsafe {
334338
match *addr {
335339
SockIpV4(ref addr) => ffi::connect(sockfd, mem::transmute(addr), mem::size_of::<sockaddr_in>() as socklen_t),
@@ -344,7 +348,8 @@ pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> {
344348
mod sa_helpers {
345349
use std::mem;
346350
use libc::{sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un};
347-
use super::{SockAddr, SockIpV6, SockIpV4, SockUnix};
351+
use super::SockAddr;
352+
use super::SockAddr::*;
348353

349354
pub fn to_sockaddr_ipv4(addr: &sockaddr_storage) -> SockAddr {
350355
let sin : &sockaddr_in = unsafe { mem::transmute(addr) };
@@ -385,6 +390,8 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> SysResult<(uint, SockAddr)> {
385390
}
386391

387392
fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result {
393+
use std::num::Int;
394+
388395
let ip_addr = Int::from_be(sin.sin_addr.s_addr);
389396
let port = Int::from_be(sin.sin_port);
390397

@@ -399,7 +406,7 @@ fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result {
399406
impl fmt::Show for SockAddr {
400407
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
401408
match *self {
402-
SockIpV4(sin) => print_ipv4_addr(&sin, f),
409+
SockAddr::SockIpV4(sin) => print_ipv4_addr(&sin, f),
403410
_ => unimplemented!()
404411
}
405412
}
@@ -420,6 +427,8 @@ fn sendto_sockaddr<T>(sockfd: Fd, buf: &[u8], flags: SockMessageFlags, addr: &T)
420427
}
421428

422429
pub fn sendto(sockfd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> SysResult<uint> {
430+
use self::SockAddr::*;
431+
423432
let ret = match *addr {
424433
SockIpV4(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr),
425434
SockIpV6(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr),
@@ -482,6 +491,8 @@ fn getsockname_sockaddr<T>(sockfd: Fd, addr: &T) -> SysResult<bool> {
482491
}
483492

484493
pub fn getsockname(sockfd: Fd, addr: &mut SockAddr) -> SysResult<bool> {
494+
use self::SockAddr::*;
495+
485496
match *addr {
486497
SockIpV4(ref addr) => getsockname_sockaddr(sockfd, addr),
487498
SockIpV6(ref addr) => getsockname_sockaddr(sockfd, addr),

src/sys/wait.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub enum WaitStatus {
2121
}
2222

2323
pub fn waitpid(pid: pid_t, options: WaitPidFlag) -> SysResult<WaitStatus> {
24+
use self::WaitStatus::*;
25+
2426
let mut status: i32 = 0;
2527

2628
let res = unsafe { ffi::waitpid(pid as pid_t, &mut status as *mut c_int, options.bits()) };

src/unistd.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::{mem, ptr};
22
use std::c_str::{CString, ToCStr};
33
use libc::{c_char, c_void, c_int, size_t, pid_t, off_t};
4-
use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC, F_SETFD, F_SETFL};
4+
use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
5+
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
6+
57
use errno::{SysResult, SysError, from_ffi};
68
use core::raw::Slice as RawSlice;
79

@@ -59,20 +61,22 @@ pub enum Fork {
5961
impl Fork {
6062
pub fn is_child(&self) -> bool {
6163
match *self {
62-
Child => true,
64+
Fork::Child => true,
6365
_ => false
6466
}
6567
}
6668

6769
pub fn is_parent(&self) -> bool {
6870
match *self {
69-
Parent(_) => true,
71+
Fork::Parent(_) => true,
7072
_ => false
7173
}
7274
}
7375
}
7476

7577
pub fn fork() -> SysResult<Fork> {
78+
use self::Fork::*;
79+
7680
let res = unsafe { ffi::fork() };
7781

7882
if res < 0 {

0 commit comments

Comments
 (0)