Skip to content

Commit 1e05db3

Browse files
committed
Converted AddressFamily to struct with associated consts
1 parent 57f90c7 commit 1e05db3

File tree

10 files changed

+911
-452
lines changed

10 files changed

+911
-452
lines changed

src/ifaddrs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,10 @@ mod tests {
200200
} else {
201201
continue;
202202
};
203-
if sock.family() == Some(crate::sys::socket::AddressFamily::Inet) {
203+
if sock.family() == crate::sys::socket::AddressFamily::INET {
204204
let _ = sock.as_sockaddr_in().unwrap();
205205
return;
206-
} else if sock.family()
207-
== Some(crate::sys::socket::AddressFamily::Inet6)
206+
} else if sock.family() == crate::sys::socket::AddressFamily::INET6
208207
{
209208
let _ = sock.as_sockaddr_in6().unwrap();
210209
return;

src/sys/epoll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::errno::Errno;
2-
use crate::Result;
32
pub use crate::poll_timeout::PollTimeout as EpollTimeout;
3+
use crate::Result;
44
use libc::{self, c_int};
55
use std::mem;
66
use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd};

src/sys/fanotify.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
//! For more documentation, please read
1111
//! [fanotify(7)](https://man7.org/linux/man-pages/man7/fanotify.7.html).
1212
13-
use crate::{NixPath, Result};
1413
use crate::errno::Errno;
15-
use crate::fcntl::{OFlag, at_rawfd};
14+
use crate::fcntl::{at_rawfd, OFlag};
1615
use crate::unistd::{close, read, write};
16+
use crate::{NixPath, Result};
1717
use std::marker::PhantomData;
18-
use std::mem::{MaybeUninit, size_of};
18+
use std::mem::{size_of, MaybeUninit};
1919
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
2020
use std::ptr;
2121

@@ -288,11 +288,16 @@ impl Fanotify {
288288
/// Returns a Result containing a Fanotify instance.
289289
///
290290
/// For more information, see [fanotify_init(2)](https://man7.org/linux/man-pages/man7/fanotify_init.2.html).
291-
pub fn init(flags: InitFlags, event_f_flags: EventFFlags) -> Result<Fanotify> {
291+
pub fn init(
292+
flags: InitFlags,
293+
event_f_flags: EventFFlags,
294+
) -> Result<Fanotify> {
292295
let res = Errno::result(unsafe {
293296
libc::fanotify_init(flags.bits(), event_f_flags.bits())
294297
});
295-
res.map(|fd| Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }})
298+
res.map(|fd| Fanotify {
299+
fd: unsafe { OwnedFd::from_raw_fd(fd) },
300+
})
296301
}
297302

298303
/// Add, remove, or modify an fanotify mark on a filesystem object.
@@ -386,22 +391,21 @@ impl Fanotify {
386391
/// available on a group that has been initialized with the flag
387392
/// `InitFlags::FAN_NONBLOCK`, thus making this method nonblocking.
388393
pub fn write_response(&self, response: FanotifyResponse) -> Result<()> {
389-
write(
390-
self.fd.as_fd(),
391-
unsafe {
392-
std::slice::from_raw_parts(
393-
(&response.inner as *const libc::fanotify_response).cast(),
394-
size_of::<libc::fanotify_response>(),
395-
)
396-
},
397-
)?;
394+
write(self.fd.as_fd(), unsafe {
395+
std::slice::from_raw_parts(
396+
(&response.inner as *const libc::fanotify_response).cast(),
397+
size_of::<libc::fanotify_response>(),
398+
)
399+
})?;
398400
Ok(())
399401
}
400402
}
401403

402404
impl FromRawFd for Fanotify {
403405
unsafe fn from_raw_fd(fd: RawFd) -> Self {
404-
Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }}
406+
Fanotify {
407+
fd: unsafe { OwnedFd::from_raw_fd(fd) },
408+
}
405409
}
406410
}
407411

src/sys/ptrace/bsd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ unsafe fn ptrace_other(
6868
addr,
6969
data,
7070
))
71-
.map(|_| 0)
71+
.map(|_| 0)
7272
}
7373
}
7474

src/sys/sendfile.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ use crate::Result;
2222
///
2323
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html) for Linux,
2424
/// see [the sendfile(2) man page.](https://docs.oracle.com/cd/E88353_01/html/E37843/sendfile-3c.html) for Solaris.
25-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "solaris", target_os = "illumos"))]
25+
#[cfg(any(
26+
target_os = "android",
27+
target_os = "linux",
28+
target_os = "solaris",
29+
target_os = "illumos"
30+
))]
2631
pub fn sendfile<F1: AsFd, F2: AsFd>(
2732
out_fd: F1,
2833
in_fd: F2,

0 commit comments

Comments
 (0)