Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer experience, cargo fmt #2528

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 44 additions & 64 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
#![deny(missing_copy_implementations)]
#![deny(missing_debug_implementations)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![deny(clippy::cast_ptr_alignment)]
#![deny(unsafe_op_in_unsafe_fn)]

Expand All @@ -105,68 +105,52 @@ mod macros;

// Public crates
#[cfg(not(target_os = "redox"))]
feature! {
#![feature = "dir"]
pub mod dir;
}
feature! {
#![feature = "env"]
pub mod env;
}
#[cfg(feature = "dir")]
pub mod dir;

#[cfg(feature = "env")]
pub mod env;

#[allow(missing_docs)]
pub mod errno;
feature! {
#![feature = "feature"]

#[deny(missing_docs)]
pub mod features;
}
#[cfg(feature = "feature")]
#[deny(missing_docs)]
pub mod features;

pub mod fcntl;
feature! {
#![feature = "net"]

#[cfg(any(linux_android,
bsd,
solarish))]
#[deny(missing_docs)]
pub mod ifaddrs;
#[cfg(not(target_os = "redox"))]
#[deny(missing_docs)]
pub mod net;
}

#[cfg(feature = "net")]
#[cfg(any(linux_android, bsd, solarish))]
#[deny(missing_docs)]
pub mod ifaddrs;

#[cfg(feature = "net")]
#[cfg(not(target_os = "redox"))]
#[deny(missing_docs)]
pub mod net;

#[cfg(linux_android)]
feature! {
#![feature = "kmod"]
pub mod kmod;
}
feature! {
#![feature = "mount"]
pub mod mount;
}
#[cfg(feature = "kmod")]
pub mod kmod;

#[cfg(feature = "mount")]
pub mod mount;

#[cfg(any(freebsdlike, target_os = "linux", target_os = "netbsd"))]
feature! {
#![feature = "mqueue"]
pub mod mqueue;
}
feature! {
#![feature = "poll"]
pub mod poll;
}
#[cfg(feature = "mqueue")]
pub mod mqueue;
#[cfg(feature = "poll")]
pub mod poll;
#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
feature! {
#![feature = "term"]
#[deny(missing_docs)]
pub mod pty;
}
feature! {
#![feature = "sched"]
pub mod sched;
}
#[cfg(feature = "term")]
#[deny(missing_docs)]
pub mod pty;
#[cfg(feature = "sched")]
pub mod sched;
pub mod sys;
feature! {
#![feature = "time"]
pub mod time;
}
#[cfg(feature = "time")]
pub mod time;
// This can be implemented for other platforms as soon as libc
// provides bindings for them.
#[cfg(all(
Expand All @@ -178,11 +162,9 @@ feature! {
target_arch = "x86_64"
)
))]
feature! {
#![feature = "ucontext"]
#[allow(missing_docs)]
pub mod ucontext;
}
#[cfg(feature = "ucontext")]
#[allow(missing_docs)]
pub mod ucontext;
pub mod unistd;

#[cfg(any(feature = "poll", feature = "event"))]
Expand All @@ -195,10 +177,8 @@ mod poll_timeout;
target_os = "netbsd",
apple_targets
))]
feature! {
#![feature = "process"]
pub mod spawn;
}
#[cfg(feature = "process")]
pub mod spawn;

use std::ffi::{CStr, CString, OsStr};
use std::mem::MaybeUninit;
Expand Down
31 changes: 12 additions & 19 deletions src/net/if_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
//! Uses Linux and/or POSIX functions to resolve interface names like "eth0"
//! or "socan1" into device numbers.

use std::{ffi::{CStr, CString}, fmt};
use crate::{errno::Errno, Error, NixPath, Result};
use libc::{c_uint, IF_NAMESIZE};
use std::{
ffi::{CStr, CString},
fmt,
};

#[cfg(not(solarish))]
/// type alias for InterfaceFlags
Expand All @@ -31,18 +34,19 @@ pub fn if_indextoname(index: c_uint) -> Result<CString> {
// We need to allocate this anyway, so doing it directly is faster.
let mut buf = vec![0u8; IF_NAMESIZE];

let return_buf = unsafe {
libc::if_indextoname(index, buf.as_mut_ptr().cast())
};
let return_buf =
unsafe { libc::if_indextoname(index, buf.as_mut_ptr().cast()) };

Errno::result(return_buf.cast())?;
Ok(CStr::from_bytes_until_nul(buf.as_slice()).unwrap().to_owned())
Ok(CStr::from_bytes_until_nul(buf.as_slice())
.unwrap()
.to_owned())
}

libc_bitflags!(
/// Standard interface flags, used by `getifaddrs`
pub struct InterfaceFlags: IflagsType {

/// Interface is running. (see
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
IFF_UP as IflagsType;
Expand Down Expand Up @@ -264,13 +268,7 @@ impl fmt::Display for InterfaceFlags {
}
}


#[cfg(any(
bsd,
target_os = "fuchsia",
target_os = "linux",
solarish,
))]
#[cfg(any(bsd, target_os = "fuchsia", target_os = "linux", solarish,))]
mod if_nameindex {
use super::*;

Expand Down Expand Up @@ -392,10 +390,5 @@ mod if_nameindex {
}
}
}
#[cfg(any(
bsd,
target_os = "fuchsia",
target_os = "linux",
solarish,
))]
#[cfg(any(bsd, target_os = "fuchsia", target_os = "linux", solarish,))]
pub use if_nameindex::*;