summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorCostin-Robert Sin <sin.costinrobert@gmail.com>2022-06-21 15:36:05 +0300
committerCostin-Robert Sin <sin.costinrobert@gmail.com>2022-06-24 00:35:52 +0300
commit3e6cb639f0d9afde57d9cc03526c2e488641231b (patch)
treec882f2947fa5b22e67a58918c45012655b892b30 /src/sys
parent8f08a69c28fad5ee875d69e4c8a1b8eed2203cb4 (diff)
downloadnix-3e6cb639f0d9afde57d9cc03526c2e488641231b.zip
Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/ioctl/bsd.rs38
-rw-r--r--src/sys/ioctl/linux.rs64
-rw-r--r--src/sys/ioctl/mod.rs52
-rw-r--r--src/sys/mod.rs88
-rw-r--r--src/sys/signal.rs379
-rw-r--r--src/sys/sysinfo.rs6
-rw-r--r--src/sys/time.rs193
7 files changed, 453 insertions, 367 deletions
diff --git a/src/sys/ioctl/bsd.rs b/src/sys/ioctl/bsd.rs
index 4ce4d332..307994cb 100644
--- a/src/sys/ioctl/bsd.rs
+++ b/src/sys/ioctl/bsd.rs
@@ -21,7 +21,7 @@ mod consts {
#[allow(overflowing_literals)]
pub const IN: ioctl_num_type = 0x8000_0000;
#[doc(hidden)]
- pub const INOUT: ioctl_num_type = IN|OUT;
+ pub const INOUT: ioctl_num_type = IN | OUT;
#[doc(hidden)]
pub const IOCPARM_MASK: ioctl_num_type = 0x1fff;
}
@@ -31,9 +31,14 @@ pub use self::consts::*;
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
- ($inout:expr, $group:expr, $num:expr, $len:expr) => (
- $inout | (($len as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as $crate::sys::ioctl::ioctl_num_type) << 8) | ($num as $crate::sys::ioctl::ioctl_num_type)
- )
+ ($inout:expr, $group:expr, $num:expr, $len:expr) => {
+ $inout
+ | (($len as $crate::sys::ioctl::ioctl_num_type
+ & $crate::sys::ioctl::IOCPARM_MASK)
+ << 16)
+ | (($group as $crate::sys::ioctl::ioctl_num_type) << 8)
+ | ($num as $crate::sys::ioctl::ioctl_num_type)
+ };
}
/// Generate an ioctl request code for a command that passes no data.
@@ -53,7 +58,9 @@ macro_rules! ioc {
/// ```
#[macro_export(local_inner_macros)]
macro_rules! request_code_none {
- ($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, 0))
+ ($g:expr, $n:expr) => {
+ ioc!($crate::sys::ioctl::VOID, $g, $n, 0)
+ };
}
/// Generate an ioctl request code for a command that passes an integer
@@ -64,7 +71,14 @@ macro_rules! request_code_none {
/// with is "bad" and you cannot use `ioctl_write_int!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write_int {
- ($g:expr, $n:expr) => (ioc!($crate::sys::ioctl::VOID, $g, $n, ::std::mem::size_of::<$crate::libc::c_int>()))
+ ($g:expr, $n:expr) => {
+ ioc!(
+ $crate::sys::ioctl::VOID,
+ $g,
+ $n,
+ ::std::mem::size_of::<$crate::libc::c_int>()
+ )
+ };
}
/// Generate an ioctl request code for a command that reads.
@@ -79,7 +93,9 @@ macro_rules! request_code_write_int {
/// writing.
#[macro_export(local_inner_macros)]
macro_rules! request_code_read {
- ($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::OUT, $g, $n, $len))
+ ($g:expr, $n:expr, $len:expr) => {
+ ioc!($crate::sys::ioctl::OUT, $g, $n, $len)
+ };
}
/// Generate an ioctl request code for a command that writes.
@@ -94,7 +110,9 @@ macro_rules! request_code_read {
/// reading.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write {
- ($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::IN, $g, $n, $len))
+ ($g:expr, $n:expr, $len:expr) => {
+ ioc!($crate::sys::ioctl::IN, $g, $n, $len)
+ };
}
/// Generate an ioctl request code for a command that reads and writes.
@@ -105,5 +123,7 @@ macro_rules! request_code_write {
/// with is "bad" and you cannot use `ioctl_readwrite!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_readwrite {
- ($g:expr, $n:expr, $len:expr) => (ioc!($crate::sys::ioctl::INOUT, $g, $n, $len))
+ ($g:expr, $n:expr, $len:expr) => {
+ ioc!($crate::sys::ioctl::INOUT, $g, $n, $len)
+ };
}
diff --git a/src/sys/ioctl/linux.rs b/src/sys/ioctl/linux.rs
index 08cd0c33..0c0a2090 100644
--- a/src/sys/ioctl/linux.rs
+++ b/src/sys/ioctl/linux.rs
@@ -14,7 +14,13 @@ pub const NRBITS: ioctl_num_type = 8;
#[doc(hidden)]
pub const TYPEBITS: ioctl_num_type = 8;
-#[cfg(any(target_arch = "mips", target_arch = "mips64", target_arch = "powerpc", target_arch = "powerpc64", target_arch = "sparc64"))]
+#[cfg(any(
+ target_arch = "mips",
+ target_arch = "mips64",
+ target_arch = "powerpc",
+ target_arch = "powerpc64",
+ target_arch = "sparc64"
+))]
mod consts {
#[doc(hidden)]
pub const NONE: u8 = 1;
@@ -29,13 +35,15 @@ mod consts {
}
// "Generic" ioctl protocol
-#[cfg(any(target_arch = "x86",
- target_arch = "arm",
- target_arch = "s390x",
- target_arch = "x86_64",
- target_arch = "aarch64",
- target_arch = "riscv32",
- target_arch = "riscv64"))]
+#[cfg(any(
+ target_arch = "x86",
+ target_arch = "arm",
+ target_arch = "s390x",
+ target_arch = "x86_64",
+ target_arch = "aarch64",
+ target_arch = "riscv32",
+ target_arch = "riscv64"
+))]
mod consts {
#[doc(hidden)]
pub const NONE: u8 = 0;
@@ -73,11 +81,20 @@ pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1;
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
- ($dir:expr, $ty:expr, $nr:expr, $sz:expr) => (
- (($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK) << $crate::sys::ioctl::DIRSHIFT) |
- (($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK) << $crate::sys::ioctl::TYPESHIFT) |
- (($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK) << $crate::sys::ioctl::NRSHIFT) |
- (($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK) << $crate::sys::ioctl::SIZESHIFT))
+ ($dir:expr, $ty:expr, $nr:expr, $sz:expr) => {
+ (($dir as $crate::sys::ioctl::ioctl_num_type
+ & $crate::sys::ioctl::DIRMASK)
+ << $crate::sys::ioctl::DIRSHIFT)
+ | (($ty as $crate::sys::ioctl::ioctl_num_type
+ & $crate::sys::ioctl::TYPEMASK)
+ << $crate::sys::ioctl::TYPESHIFT)
+ | (($nr as $crate::sys::ioctl::ioctl_num_type
+ & $crate::sys::ioctl::NRMASK)
+ << $crate::sys::ioctl::NRSHIFT)
+ | (($sz as $crate::sys::ioctl::ioctl_num_type
+ & $crate::sys::ioctl::SIZEMASK)
+ << $crate::sys::ioctl::SIZESHIFT)
+ };
}
/// Generate an ioctl request code for a command that passes no data.
@@ -97,7 +114,9 @@ macro_rules! ioc {
/// ```
#[macro_export(local_inner_macros)]
macro_rules! request_code_none {
- ($ty:expr, $nr:expr) => (ioc!($crate::sys::ioctl::NONE, $ty, $nr, 0))
+ ($ty:expr, $nr:expr) => {
+ ioc!($crate::sys::ioctl::NONE, $ty, $nr, 0)
+ };
}
/// Generate an ioctl request code for a command that reads.
@@ -112,7 +131,9 @@ macro_rules! request_code_none {
/// writing.
#[macro_export(local_inner_macros)]
macro_rules! request_code_read {
- ($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::READ, $ty, $nr, $sz))
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ ioc!($crate::sys::ioctl::READ, $ty, $nr, $sz)
+ };
}
/// Generate an ioctl request code for a command that writes.
@@ -127,7 +148,9 @@ macro_rules! request_code_read {
/// reading.
#[macro_export(local_inner_macros)]
macro_rules! request_code_write {
- ($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::WRITE, $ty, $nr, $sz))
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ ioc!($crate::sys::ioctl::WRITE, $ty, $nr, $sz)
+ };
}
/// Generate an ioctl request code for a command that reads and writes.
@@ -138,5 +161,12 @@ macro_rules! request_code_write {
/// with is "bad" and you cannot use `ioctl_readwrite!()` directly.
#[macro_export(local_inner_macros)]
macro_rules! request_code_readwrite {
- ($ty:expr, $nr:expr, $sz:expr) => (ioc!($crate::sys::ioctl::READ | $crate::sys::ioctl::WRITE, $ty, $nr, $sz))
+ ($ty:expr, $nr:expr, $sz:expr) => {
+ ioc!(
+ $crate::sys::ioctl::READ | $crate::sys::ioctl::WRITE,
+ $ty,
+ $nr,
+ $sz
+ )
+ };
}
diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs
index ce9c5db0..98d6b5c9 100644
--- a/src/sys/ioctl/mod.rs
+++ b/src/sys/ioctl/mod.rs
@@ -227,39 +227,45 @@ use cfg_if::cfg_if;
#[macro_use]
mod linux;
-#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
+#[cfg(any(
+ target_os = "android",
+ target_os = "linux",
+ target_os = "redox"
+))]
pub use self::linux::*;
-#[cfg(any(target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "illumos",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "haiku",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "illumos",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "haiku",
+ target_os = "openbsd"
+))]
#[macro_use]
mod bsd;
-#[cfg(any(target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "illumos",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "haiku",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "illumos",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "haiku",
+ target_os = "openbsd"
+))]
pub use self::bsd::*;
/// Convert raw ioctl return value to a Nix result
#[macro_export]
#[doc(hidden)]
macro_rules! convert_ioctl_res {
- ($w:expr) => (
- {
- $crate::errno::Errno::result($w)
- }
- );
+ ($w:expr) => {{
+ $crate::errno::Errno::result($w)
+ }};
}
/// Generates a wrapper function for an ioctl that passes no data to the kernel.
@@ -491,7 +497,7 @@ macro_rules! ioctl_write_ptr_bad {
)
}
-cfg_if!{
+cfg_if! {
if #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] {
/// Generates a wrapper function for a ioctl that writes an integer to the kernel.
///
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 9f0d037e..ddd4fdfc 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -1,10 +1,12 @@
//! Mostly platform-specific functionality
-#[cfg(any(target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- all(target_os = "linux", not(target_env = "uclibc")),
- target_os = "macos",
- target_os = "netbsd"))]
+#[cfg(any(
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "ios",
+ all(target_os = "linux", not(target_env = "uclibc")),
+ target_os = "macos",
+ target_os = "netbsd"
+))]
feature! {
#![feature = "aio"]
pub mod aio;
@@ -31,16 +33,18 @@ feature! {
pub mod eventfd;
}
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "linux",
- target_os = "redox",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "illumos",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "linux",
+ target_os = "redox",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "illumos",
+ target_os = "openbsd"
+))]
#[cfg(feature = "ioctl")]
#[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))]
#[macro_use]
@@ -69,13 +73,15 @@ feature! {
pub mod pthread;
}
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
+#[cfg(any(
+ target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"
+))]
feature! {
#![feature = "ptrace"]
#[allow(missing_docs)]
@@ -94,7 +100,12 @@ feature! {
pub mod reboot;
}
-#[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "illumos", target_os = "haiku")))]
+#[cfg(not(any(
+ target_os = "redox",
+ target_os = "fuchsia",
+ target_os = "illumos",
+ target_os = "haiku"
+)))]
feature! {
#![feature = "resource"]
pub mod resource;
@@ -106,12 +117,14 @@ feature! {
pub mod select;
}
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "linux",
- target_os = "macos"))]
+#[cfg(any(
+ target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "linux",
+ target_os = "macos"
+))]
feature! {
#![feature = "zerocopy"]
pub mod sendfile;
@@ -139,13 +152,14 @@ feature! {
pub mod stat;
}
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "linux",
- target_os = "macos",
- target_os = "openbsd"
+#[cfg(any(
+ target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "linux",
+ target_os = "macos",
+ target_os = "openbsd"
))]
feature! {
#![feature = "fs"]
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 9a4e90e4..f6a8c2d7 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -3,22 +3,22 @@
//! Operating system signals.
-use crate::{Error, Result};
use crate::errno::Errno;
-use std::mem;
+use crate::{Error, Result};
+use cfg_if::cfg_if;
use std::fmt;
-use std::str::FromStr;
+use std::mem;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
use std::ptr;
-use cfg_if::cfg_if;
+use std::str::FromStr;
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
#[cfg(any(feature = "aio", feature = "signal"))]
pub use self::sigevent::*;
#[cfg(any(feature = "aio", feature = "process", feature = "signal"))]
-libc_enum!{
+libc_enum! {
/// Types of operating system signals
// Currently there is only one definition of c_int in libc, as well as only one
// type for signal constants.
@@ -135,10 +135,19 @@ impl FromStr for Signal {
"SIGPIPE" => Signal::SIGPIPE,
"SIGALRM" => Signal::SIGALRM,
"SIGTERM" => Signal::SIGTERM,
- #[cfg(all(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux"),
- not(any(target_arch = "mips", target_arch = "mips64",
- target_arch = "sparc64"))))]
+ #[cfg(all(
+ any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux"
+ ),
+ not(any(
+ target_arch = "mips",
+ target_arch = "mips64",
+ target_arch = "sparc64"
+ ))
+ ))]
"SIGSTKFLT" => Signal::SIGSTKFLT,
"SIGCHLD" => Signal::SIGCHLD,
"SIGCONT" => Signal::SIGCONT,
@@ -154,17 +163,31 @@ impl FromStr for Signal {
"SIGWINCH" => Signal::SIGWINCH,
#[cfg(not(target_os = "haiku"))]
"SIGIO" => Signal::SIGIO,
- #[cfg(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux"))]
+ #[cfg(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux"
+ ))]
"SIGPWR" => Signal::SIGPWR,
"SIGSYS" => Signal::SIGSYS,
- #[cfg(not(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux",
- target_os = "redox", target_os = "haiku")))]
+ #[cfg(not(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux",
+ target_os = "redox",
+ target_os = "haiku"
+ )))]
"SIGEMT" => Signal::SIGEMT,
- #[cfg(not(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux",
- target_os = "redox", target_os = "haiku")))]
+ #[cfg(not(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux",
+ target_os = "redox",
+ target_os = "haiku"
+ )))]
"SIGINFO" => Signal::SIGINFO,
_ => return Err(Errno::EINVAL),
})
@@ -195,9 +218,19 @@ impl Signal {
Signal::SIGPIPE => "SIGPIPE",
Signal::SIGALRM => "SIGALRM",
Signal::SIGTERM => "SIGTERM",
- #[cfg(all(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux"),
- not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))]
+ #[cfg(all(
+ any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux"
+ ),
+ not(any(
+ target_arch = "mips",
+ target_arch = "mips64",
+ target_arch = "sparc64"
+ ))
+ ))]
Signal::SIGSTKFLT => "SIGSTKFLT",
Signal::SIGCHLD => "SIGCHLD",
Signal::SIGCONT => "SIGCONT",
@@ -213,17 +246,31 @@ impl Signal {
Signal::SIGWINCH => "SIGWINCH",
#[cfg(not(target_os = "haiku"))]
Signal::SIGIO => "SIGIO",
- #[cfg(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux"))]
+ #[cfg(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux"
+ ))]
Signal::SIGPWR => "SIGPWR",
Signal::SIGSYS => "SIGSYS",
- #[cfg(not(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux",
- target_os = "redox", target_os = "haiku")))]
+ #[cfg(not(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux",
+ target_os = "redox",
+ target_os = "haiku"
+ )))]
Signal::SIGEMT => "SIGEMT",
- #[cfg(not(any(target_os = "android", target_os = "emscripten",
- target_os = "fuchsia", target_os = "linux",
- target_os = "redox", target_os = "haiku")))]
+ #[cfg(not(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia",
+ target_os = "linux",
+ target_os = "redox",
+ target_os = "haiku"
+ )))]
Signal::SIGINFO => "SIGINFO",
}
}
@@ -249,175 +296,70 @@ pub use self::Signal::*;
#[cfg(target_os = "redox")]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 29] = [
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGABRT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGSYS];
+ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
+ SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
+ SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
+ SIGPROF, SIGWINCH, SIGIO, SIGSYS,
+];
#[cfg(target_os = "haiku")]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 28] = [
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGABRT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGSYS];
-#[cfg(all(any(target_os = "linux", target_os = "android",
- target_os = "emscripten", target_os = "fuchsia"),
- not(any(target_arch = "mips", target_arch = "mips64",
- target_arch = "sparc64"))))]
+ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
+ SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
+ SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
+ SIGPROF, SIGWINCH, SIGSYS,
+];
+#[cfg(all(
+ any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia"
+ ),
+ not(any(
+ target_arch = "mips",
+ target_arch = "mips64",
+ target_arch = "sparc64"
+ ))
+))]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGABRT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- SIGSTKFLT,
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGPWR,
- SIGSYS];
-#[cfg(all(any(target_os = "linux", target_os = "android",
- target_os = "emscripten", target_os = "fuchsia"),
- any(target_arch = "mips", target_arch = "mips64",
- target_arch = "sparc64")))]
+ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
+ SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGSTKFLT, SIGCHLD,
+ SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ,
+ SIGVTALRM, SIGPROF, SIGWINCH, SIGIO, SIGPWR, SIGSYS,
+];
+#[cfg(all(
+ any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "fuchsia"
+ ),
+ any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64")
+))]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 30] = [
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGABRT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGPWR,
- SIGSYS];
-#[cfg(not(any(target_os = "linux", target_os = "android",
- target_os = "fuchsia", target_os = "emscripten",
- target_os = "redox", target_os = "haiku")))]
+ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
+ SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
+ SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
+ SIGPROF, SIGWINCH, SIGIO, SIGPWR, SIGSYS,
+];
+#[cfg(not(any(
+ target_os = "linux",
+ target_os = "android",
+ target_os = "fuchsia",
+ target_os = "emscripten",
+ target_os = "redox",
+ target_os = "haiku"
+)))]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
- SIGHUP,
- SIGINT,
- SIGQUIT,
- SIGILL,
- SIGTRAP,
- SIGABRT,
- SIGBUS,
- SIGFPE,
- SIGKILL,
- SIGUSR1,
- SIGSEGV,
- SIGUSR2,
- SIGPIPE,
- SIGALRM,
- SIGTERM,
- SIGCHLD,
- SIGCONT,
- SIGSTOP,
- SIGTSTP,
- SIGTTIN,
- SIGTTOU,
- SIGURG,
- SIGXCPU,
- SIGXFSZ,
- SIGVTALRM,
- SIGPROF,
- SIGWINCH,
- SIGIO,
- SIGSYS,
- SIGEMT,
- SIGINFO];
+ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
+ SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
+ SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
+ SIGPROF, SIGWINCH, SIGIO, SIGSYS, SIGEMT, SIGINFO,
+];
feature! {
#![feature = "signal"]
@@ -469,7 +411,7 @@ cfg_if! {
}
#[cfg(feature = "signal")]
-libc_bitflags!{
+libc_bitflags! {
/// Controls the behavior of a [`SigAction`]
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
pub struct SaFlags: SaFlags_t {
@@ -1001,7 +943,6 @@ pub fn raise(signal: Signal) -> Result<()> {
}
}
-
feature! {
#![any(feature = "aio", feature = "signal")]
@@ -1161,9 +1102,9 @@ mod sigevent {
#[cfg(test)]
mod tests {
+ use super::*;
#[cfg(not(target_os = "redox"))]
use std::thread;
- use super::*;
#[test]
fn test_contains() {
@@ -1227,14 +1168,18 @@ mod tests {
test_mask.add(SIGUSR1);
assert!(test_mask.thread_set_mask().is_ok());
- let new_mask = SigSet::thread_get_mask()
- .expect("Failed to get new mask!");
+ let new_mask =
+ SigSet::thread_get_mask().expect("Failed to get new mask!");
assert!(new_mask.contains(SIGUSR1));
assert!(!new_mask.contains(SIGUSR2));
- prev_mask.thread_set_mask().expect("Failed to revert signal mask!");
- }).join().unwrap();
+ prev_mask
+ .thread_set_mask()
+ .expect("Failed to revert signal mask!");
+ })
+ .join()
+ .unwrap();
}
#[test]
@@ -1247,7 +1192,9 @@ mod tests {
assert!(mask.thread_block().is_ok());
assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
- }).join().unwrap();
+ })
+ .join()
+ .unwrap();
}
#[test]
@@ -1260,7 +1207,9 @@ mod tests {
assert!(mask.thread_unblock().is_ok());
assert!(!SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
- }).join().unwrap();
+ })
+ .join()
+ .unwrap();
}
#[test]
@@ -1276,14 +1225,16 @@ mod tests {
let mut mask2 = SigSet::empty();
mask2.add(SIGUSR2);
- let oldmask = mask2.thread_swap_mask(SigmaskHow::SIG_SETMASK)
- .unwrap();
+ let oldmask =
+ mask2.thread_swap_mask(SigmaskHow::SIG_SETMASK).unwrap();
assert!(oldmask.contains(SIGUSR1));
assert!(!oldmask.contains(SIGUSR2));
assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR2));
- }).join().unwrap();
+ })
+ .join()
+ .unwrap();
}
#[test]
@@ -1297,22 +1248,28 @@ mod tests {
#[cfg(not(target_os = "redox"))]
fn test_sigaction() {
thread::spawn(|| {
- extern fn test_sigaction_handler(_: libc::c_int) {}
- extern fn test_sigaction_action(_: libc::c_int,
- _: *mut libc::siginfo_t, _: *mut libc::c_void) {}
+ extern "C" fn test_sigaction_handler(_: libc::c_int) {}
+ extern "C" fn test_sigaction_action(
+ _: libc::c_int,
+ _: *mut libc::siginfo_t,
+ _: *mut libc::c_void,
+ ) {
+ }
let handler_sig = SigHandler::Handler(test_sigaction_handler);
- let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART |
- SaFlags::SA_SIGINFO;
+ let flags =
+ SaFlags::SA_ONSTACK | SaFlags::SA_RESTART | SaFlags::SA_SIGINFO;
let mut mask = SigSet::empty();
mask.add(SIGUSR1);
let action_sig = SigAction::new(handler_sig, flags, mask);
- assert_eq!(action_sig.flags(),
- SaFlags::SA_ONSTACK | SaFlags::SA_RESTART);
+ assert_eq!(
+ action_sig.flags(),
+ SaFlags::SA_ONSTACK | SaFlags::SA_RESTART
+ );
assert_eq!(action_sig.handler(), handler_sig);
mask = action_sig.mask();
@@ -1328,7 +1285,9 @@ mod tests {
let action_ign = SigAction::new(SigHandler::SigIgn, flags, mask);
assert_eq!(action_ign.handler(), SigHandler::SigIgn);
- }).join().unwrap();
+ })
+ .join()
+ .unwrap();
}
#[test]
@@ -1342,6 +1301,8 @@ mod tests {
raise(SIGUSR1).unwrap();
assert_eq!(mask.wait().unwrap(), SIGUSR1);
- }).join().unwrap();
+ })
+ .join()
+ .unwrap();
}
}
diff --git a/src/sys/sysinfo.rs b/src/sys/sysinfo.rs
index dc943c1a..96f04330 100644
--- a/src/sys/sysinfo.rs
+++ b/src/sys/sysinfo.rs
@@ -1,9 +1,9 @@
use libc::{self, SI_LOAD_SHIFT};
-use std::{cmp, mem};
use std::time::Duration;
+use std::{cmp, mem};
-use crate::Result;
use crate::errno::Errno;
+use crate::Result;
/// System info structure returned by `sysinfo`.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
@@ -75,5 +75,5 @@ impl SysInfo {
pub fn sysinfo() -> Result<SysInfo> {
let mut info = mem::MaybeUninit::uninit();
let res = unsafe { libc::sysinfo(info.as_mut_ptr()) };
- Errno::result(res).map(|_| unsafe{ SysInfo(info.assume_init()) })
+ Errno::result(res).map(|_| unsafe { SysInfo(info.assume_init()) })
}
diff --git a/src/sys/time.rs b/src/sys/time.rs
index c29259b2..c559cc47 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -1,9 +1,10 @@
-use std::{cmp, fmt, ops};
-use std::time::Duration;
-use std::convert::From;
+#[cfg_attr(target_env = "musl", allow(deprecated))]
+// https://github.com/rust-lang/libc/issues/1848
+pub use libc::{suseconds_t, time_t};
use libc::{timespec, timeval};
-#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
-pub use libc::{time_t, suseconds_t};
+use std::convert::From;
+use std::time::Duration;
+use std::{cmp, fmt, ops};
#[cfg(any(
all(feature = "time", any(target_os = "android", target_os = "linux")),
@@ -62,10 +63,12 @@ pub(crate) mod timer {
},
it_value: *t.as_ref(),
}),
- Expiration::IntervalDelayed(start, interval) => TimerSpec(libc::itimerspec {
- it_interval: *interval.as_ref(),
- it_value: *start.as_ref(),
- }),
+ Expiration::IntervalDelayed(start, interval) => {
+ TimerSpec(libc::itimerspec {
+ it_interval: *interval.as_ref(),
+ it_value: *start.as_ref(),
+ })
+ }
Expiration::Interval(t) => TimerSpec(libc::itimerspec {
it_interval: *t.as_ref(),
it_value: *t.as_ref(),
@@ -94,7 +97,12 @@ pub(crate) mod timer {
const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME;
}
}
- #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "dragonfly", target_os = "illumos"))]
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "netbsd",
+ target_os = "dragonfly",
+ target_os = "illumos"
+ ))]
bitflags! {
/// Flags that are used for arming the timer.
pub struct TimerSetTimeFlags: libc::c_int {
@@ -117,10 +125,15 @@ pub(crate) mod timer {
it_interval: int_ts,
it_value: val_ts,
}) => {
- if (int_ts.tv_sec == val_ts.tv_sec) && (int_ts.tv_nsec == val_ts.tv_nsec) {
+ if (int_ts.tv_sec == val_ts.tv_sec)
+ && (int_ts.tv_nsec == val_ts.tv_nsec)
+ {
Expiration::Interval(int_ts.into())
} else {
- Expiration::IntervalDelayed(val_ts.into(), int_ts.into())
+ Expiration::IntervalDelayed(
+ val_ts.into(),
+ int_ts.into(),
+ )
}
}
}
@@ -136,14 +149,16 @@ pub trait TimeValLike: Sized {
#[inline]
fn hours(hours: i64) -> Self {
- let secs = hours.checked_mul(SECS_PER_HOUR)
+ let secs = hours
+ .checked_mul(SECS_PER_HOUR)
.expect("TimeValLike::hours ouf of bounds");
Self::seconds(secs)
}
#[inline]
fn minutes(minutes: i64) -> Self {
- let secs = minutes.checked_mul(SECS_PER_MINUTE)
+ let secs = minutes
+ .checked_mul(SECS_PER_MINUTE)
.expect("TimeValLike::minutes out of bounds");
Self::seconds(secs)
}
@@ -243,15 +258,23 @@ impl PartialOrd for TimeSpec {
impl TimeValLike for TimeSpec {
#[inline]
fn seconds(seconds: i64) -> TimeSpec {
- assert!((TS_MIN_SECONDS..=TS_MAX_SECONDS).contains(&seconds),
- "TimeSpec out of bounds; seconds={}", seconds);
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeSpec(timespec {tv_sec: seconds as time_t, tv_nsec: 0 })
+ assert!(
+ (TS_MIN_SECONDS..=TS_MAX_SECONDS).contains(&seconds),
+ "TimeSpec out of bounds; seconds={}",
+ seconds
+ );
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
+ TimeSpec(timespec {
+ tv_sec: seconds as time_t,
+ tv_nsec: 0,
+ })
}
#[inline]
fn milliseconds(milliseconds: i64) -> TimeSpec {
- let nanoseconds = milliseconds.checked_mul(1_000_000)
+ let nanoseconds = milliseconds
+ .checked_mul(1_000_000)
.expect("TimeSpec::milliseconds out of bounds");
TimeSpec::nanoseconds(nanoseconds)
@@ -260,7 +283,8 @@ impl TimeValLike for TimeSpec {
/// Makes a new `TimeSpec` with given number of microseconds.
#[inline]
fn microseconds(microseconds: i64) -> TimeSpec {
- let nanoseconds = microseconds.checked_mul(1_000)
+ let nanoseconds = microseconds
+ .checked_mul(1_000)
.expect("TimeSpec::milliseconds out of bounds");
TimeSpec::nanoseconds(nanoseconds)
@@ -270,11 +294,16 @@ impl TimeValLike for TimeSpec {
#[inline]
fn nanoseconds(nanoseconds: i64) -> TimeSpec {
let (secs, nanos) = div_mod_floor_64(nanoseconds, NANOS_PER_SEC);
- assert!((TS_MIN_SECONDS..=TS_MAX_SECONDS).contains(&secs),
- "TimeSpec out of bounds");
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeSpec(timespec {tv_sec: secs as time_t,
- tv_nsec: nanos as timespec_tv_nsec_t })
+ assert!(
+ (TS_MIN_SECONDS..=TS_MAX_SECONDS).contains(&secs),
+ "TimeSpec out of bounds"
+ );
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
+ TimeSpec(timespec {
+ tv_sec: secs as time_t,
+ tv_nsec: nanos as timespec_tv_nsec_t,
+ })
}
fn num_seconds(&self) -> i64 {
@@ -319,10 +348,11 @@ impl TimeSpec {
}
pub const fn from_duration(duration: Duration) -> Self {
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {
tv_sec: duration.as_secs() as time_t,
- tv_nsec: duration.subsec_nanos() as timespec_tv_nsec_t
+ tv_nsec: duration.subsec_nanos() as timespec_tv_nsec_t,
})
}
@@ -343,8 +373,7 @@ impl ops::Add for TimeSpec {
type Output = TimeSpec;
fn add(self, rhs: TimeSpec) -> TimeSpec {
- TimeSpec::nanoseconds(
- self.num_nanoseconds() + rhs.num_nanoseconds())
+ TimeSpec::nanoseconds(self.num_nanoseconds() + rhs.num_nanoseconds())
}
}
@@ -352,8 +381,7 @@ impl ops::Sub for TimeSpec {
type Output = TimeSpec;
fn sub(self, rhs: TimeSpec) -> TimeSpec {
- TimeSpec::nanoseconds(
- self.num_nanoseconds() - rhs.num_nanoseconds())
+ TimeSpec::nanoseconds(self.num_nanoseconds() - rhs.num_nanoseconds())
}
}
@@ -361,7 +389,9 @@ impl ops::Mul<i32> for TimeSpec {
type Output = TimeSpec;
fn mul(self, rhs: i32) -> TimeSpec {
- let usec = self.num_nanoseconds().checked_mul(i64::from(rhs))
+ let usec = self
+ .num_nanoseconds()
+ .checked_mul(i64::from(rhs))
.expect("TimeSpec multiply out of bounds");
TimeSpec::nanoseconds(usec)
@@ -407,8 +437,6 @@ impl fmt::Display for TimeSpec {
}
}
-
-
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct TimeVal(timeval);
@@ -456,15 +484,23 @@ impl PartialOrd for TimeVal {
impl TimeValLike for TimeVal {
#[inline]
fn seconds(seconds: i64) -> TimeVal {
- assert!((TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&seconds),
- "TimeVal out of bounds; seconds={}", seconds);
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeVal(timeval {tv_sec: seconds as time_t, tv_usec: 0 })
+ assert!(
+ (TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&seconds),
+ "TimeVal out of bounds; seconds={}",
+ seconds
+ );
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
+ TimeVal(timeval {
+ tv_sec: seconds as time_t,
+ tv_usec: 0,
+ })
}
#[inline]
fn milliseconds(milliseconds: i64) -> TimeVal {
- let microseconds = milliseconds.checked_mul(1_000)
+ let microseconds = milliseconds
+ .checked_mul(1_000)
.expect("TimeVal::milliseconds out of bounds");
TimeVal::microseconds(microseconds)
@@ -474,11 +510,16 @@ impl TimeValLike for TimeVal {
#[inline]
fn microseconds(microseconds: i64) -> TimeVal {
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
- assert!((TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
- "TimeVal out of bounds");
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeVal(timeval {tv_sec: secs as time_t,
- tv_usec: micros as suseconds_t })
+ assert!(
+ (TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
+ "TimeVal out of bounds"
+ );
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
+ TimeVal(timeval {
+ tv_sec: secs as time_t,
+ tv_usec: micros as suseconds_t,
+ })
}
/// Makes a new `TimeVal` with given number of nanoseconds. Some precision
@@ -487,11 +528,16 @@ impl TimeValLike for TimeVal {
fn nanoseconds(nanoseconds: i64) -> TimeVal {
let microseconds = nanoseconds / 1000;
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
- assert!((TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
- "TimeVal out of bounds");
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeVal(timeval {tv_sec: secs as time_t,
- tv_usec: micros as suseconds_t })
+ assert!(
+ (TV_MIN_SECONDS..=TV_MAX_SECONDS).contains(&secs),
+ "TimeVal out of bounds"
+ );
+ #[cfg_attr(target_env = "musl", allow(deprecated))]
+ // https://github.com/rust-lang/libc/issues/1848
+ TimeVal(timeval {
+ tv_sec: secs as time_t,
+ tv_usec: micros as suseconds_t,
+ })
}
fn num_seconds(&self) -> i64 {
@@ -548,8 +594,7 @@ impl ops::Add for TimeVal {
type Output = TimeVal;
fn add(self, rhs: TimeVal) -> TimeVal {
- TimeVal::microseconds(
- self.num_microseconds() + rhs.num_microseconds())
+ TimeVal::microseconds(self.num_microseconds() + rhs.num_microseconds())
}
}
@@ -557,8 +602,7 @@ impl ops::Sub for TimeVal {
type Output = TimeVal;
fn sub(self, rhs: TimeVal) -> TimeVal {
- TimeVal::microseconds(
- self.num_microseconds() - rhs.num_microseconds())
+ TimeVal::microseconds(self.num_microseconds() - rhs.num_microseconds())
}
}
@@ -566,7 +610,9 @@ impl ops::Mul<i32> for TimeVal {
type Output = TimeVal;
fn mul(self, rhs: i32) -> TimeVal {
- let usec = self.num_microseconds().checked_mul(i64::from(rhs))
+ let usec = self
+ .num_microseconds()
+ .checked_mul(i64::from(rhs))
.expect("TimeVal multiply out of bounds");
TimeVal::microseconds(usec)
@@ -624,18 +670,16 @@ fn div_mod_floor_64(this: i64, other: i64) -> (i64, i64) {
#[inline]
fn div_floor_64(this: i64, other: i64) -> i64 {
match div_rem_64(this, other) {
- (d, r) if (r > 0 && other < 0)
- || (r < 0 && other > 0) => d - 1,
- (d, _) => d,
+ (d, r) if (r > 0 && other < 0) || (r < 0 && other > 0) => d - 1,
+ (d, _) => d,
}
}
#[inline]
fn mod_floor_64(this: i64, other: i64) -> i64 {
match this % other {
- r if (r > 0 && other < 0)
- || (r < 0 && other > 0) => r + other,
- r => r,
+ r if (r > 0 && other < 0) || (r < 0 && other > 0) => r + other,
+ r => r,
}
}
@@ -652,10 +696,14 @@ mod test {
#[test]
pub fn test_timespec() {
assert!(TimeSpec::seconds(1) != TimeSpec::zero());
- assert_eq!(TimeSpec::seconds(1) + TimeSpec::seconds(2),
- TimeSpec::seconds(3));
- assert_eq!(TimeSpec::minutes(3) + TimeSpec::seconds(2),
- TimeSpec::seconds(182));
+ assert_eq!(
+ TimeSpec::seconds(1) + TimeSpec::seconds(2),
+ TimeSpec::seconds(3)
+ );
+ assert_eq!(
+ TimeSpec::minutes(3) + TimeSpec::seconds(2),
+ TimeSpec::seconds(182)
+ );
}
#[test]
@@ -690,17 +738,24 @@ mod test {
assert_eq!(TimeSpec::seconds(42).to_string(), "42 seconds");
assert_eq!(TimeSpec::milliseconds(42).to_string(), "0.042 seconds");
assert_eq!(TimeSpec::microseconds(42).to_string(), "0.000042 seconds");
- assert_eq!(TimeSpec::nanoseconds(42).to_string(), "0.000000042 seconds");
+ assert_eq!(
+ TimeSpec::nanoseconds(42).to_string(),
+ "0.000000042 seconds"
+ );
assert_eq!(TimeSpec::seconds(-86401).to_string(), "-86401 seconds");
}
#[test]
pub fn test_timeval() {
assert!(TimeVal::seconds(1) != TimeVal::zero());
- assert_eq!(TimeVal::seconds(1) + TimeVal::seconds(2),
- TimeVal::seconds(3));
- assert_eq!(TimeVal::minutes(3) + TimeVal::seconds(2),
- TimeVal::seconds(182));
+ assert_eq!(
+ TimeVal::seconds(1) + TimeVal::seconds(2),
+ TimeVal::seconds(3)
+ );
+ assert_eq!(
+ TimeVal::minutes(3) + TimeVal::seconds(2),
+ TimeVal::seconds(182)
+ );
}
#[test]