Skip to content

Commit

Permalink
refactor: fix clippy & unused imports/helper type (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored May 25, 2024
1 parent 1dad4d8 commit c003ae9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub type Result<T> = result::Result<T, Errno>;
/// * `Eq`
/// * Small size
/// * Represents all of the system's errnos, instead of just the most common
/// ones.
/// ones.
pub type Error = Errno;

/// Common trait used to represent file system paths by many Nix functions.
Expand Down
5 changes: 4 additions & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ mod sched_linux_like {
let ptr = stack.as_mut_ptr().add(stack.len());
let ptr_aligned = ptr.sub(ptr as usize % 16);
libc::clone(
mem::transmute(
mem::transmute::<
extern "C" fn(*mut Box<dyn FnMut() -> isize>) -> i32,
extern "C" fn(*mut libc::c_void) -> i32,
>(
callback
as extern "C" fn(*mut Box<dyn FnMut() -> isize>) -> i32,
),
Expand Down
24 changes: 21 additions & 3 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ use crate::sys::time::TimeVal;
use crate::Result;
use cfg_if::cfg_if;
use libc::{self, c_int, c_void, socklen_t};
use std::ffi::{CStr, CString, OsStr, OsString};
#[cfg(apple_targets)]
use std::ffi::{CStr, CString};
#[cfg(any(target_os = "freebsd", linux_android))]
use std::ffi::{OsStr, OsString};
use std::mem::{self, MaybeUninit};
#[cfg(any(target_os = "freebsd", linux_android))]
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsFd, AsRawFd};

Expand Down Expand Up @@ -749,7 +753,12 @@ sockopt_impl!(
libc::SO_TIMESTAMPING,
super::TimestampingFlag
);
#[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "hurd", target_os = "redox")))]
#[cfg(not(any(
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "redox"
)))]
sockopt_impl!(
/// Enable or disable the receiving of the `SO_TIMESTAMP` control message.
ReceiveTimestamp,
Expand Down Expand Up @@ -1300,7 +1309,6 @@ impl SetSockOpt for TcpTlsRx {
}
}


/*
*
* ===== Accessor helpers =====
Expand Down Expand Up @@ -1438,11 +1446,13 @@ impl<'a> Set<'a, bool> for SetBool {
}

/// Getter for an `u8` value.
#[cfg(feature = "net")]
struct GetU8 {
len: socklen_t,
val: MaybeUninit<u8>,
}

#[cfg(feature = "net")]
impl Get<u8> for GetU8 {
fn uninit() -> Self {
GetU8 {
Expand Down Expand Up @@ -1470,10 +1480,12 @@ impl Get<u8> for GetU8 {
}

/// Setter for an `u8` value.
#[cfg(feature = "net")]
struct SetU8 {
val: u8,
}

#[cfg(feature = "net")]
impl<'a> Set<'a, u8> for SetU8 {
fn new(val: &'a u8) -> SetU8 {
SetU8 { val: *val }
Expand Down Expand Up @@ -1540,11 +1552,13 @@ impl<'a> Set<'a, usize> for SetUsize {
}

/// Getter for a `OsString` value.
#[cfg(any(target_os = "freebsd", linux_android))]
struct GetOsString<T: AsMut<[u8]>> {
len: socklen_t,
val: MaybeUninit<T>,
}

#[cfg(any(target_os = "freebsd", linux_android))]
impl<T: AsMut<[u8]>> Get<OsString> for GetOsString<T> {
fn uninit() -> Self {
GetOsString {
Expand All @@ -1569,10 +1583,12 @@ impl<T: AsMut<[u8]>> Get<OsString> for GetOsString<T> {
}

/// Setter for a `OsString` value.
#[cfg(any(target_os = "freebsd", linux_android))]
struct SetOsString<'a> {
val: &'a OsStr,
}

#[cfg(any(target_os = "freebsd", linux_android))]
impl<'a> Set<'a, OsString> for SetOsString<'a> {
fn new(val: &'a OsString) -> SetOsString {
SetOsString {
Expand All @@ -1590,11 +1606,13 @@ impl<'a> Set<'a, OsString> for SetOsString<'a> {
}

/// Getter for a `CString` value.
#[cfg(apple_targets)]
struct GetCString<T: AsMut<[u8]>> {
len: socklen_t,
val: MaybeUninit<T>,
}

#[cfg(apple_targets)]
impl<T: AsMut<[u8]>> Get<CString> for GetCString<T> {
fn uninit() -> Self {
GetCString {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Timer {
/// There are 3 types of alarms you can set:
///
/// - one shot: the alarm will trigger once after the specified amount of
/// time.
/// time.
/// Example: I want an alarm to go off in 60s and then disable itself.
///
/// - interval: the alarm will trigger every specified interval of time.
Expand Down
2 changes: 1 addition & 1 deletion src/sys/timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TimerFd {
/// There are 3 types of alarms you can set:
///
/// - one shot: the alarm will trigger once after the specified amount of
/// time.
/// time.
/// Example: I want an alarm to go off in 60s and then disable itself.
///
/// - interval: the alarm will trigger every specified interval of time.
Expand Down

0 comments on commit c003ae9

Please sign in to comment.