Skip to content

Commit 089b87a

Browse files
authored
Merge pull request #287 from fox0/clippy--new_ret_no_self
Fix clippy::new_ret_no_self
2 parents 51f6e33 + ab418ba commit 089b87a

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

process/fuser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ mod linux {
607607

608608
Ok(())
609609
}
610+
610611
/// Checks a directory within a process's `/proc` entry for matching devices and inodes,
611612
/// and updates the `Names` object with relevant process information.
612613
///
@@ -629,6 +630,7 @@ mod linux {
629630
/// # Returns
630631
///
631632
/// Returns `Ok(())` on success.
633+
#[allow(clippy::too_many_arguments)]
632634
fn check_dir(
633635
names: &mut Names,
634636
pid: i32,
@@ -695,6 +697,7 @@ mod linux {
695697

696698
Ok(())
697699
}
700+
698701
/// Checks the memory map of a process for matching devices and updates the `Names` object.
699702
///
700703
/// # Arguments

users/talk.rs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -205,35 +205,38 @@ pub struct Osockaddr {
205205
pub sa_data: [u8; 14],
206206
}
207207

208-
impl Osockaddr {
209-
// Converts the packed address structure into a SocketAddrV4
210-
pub fn to_socketaddr(&self) -> Option<SocketAddrV4> {
208+
impl From<&Osockaddr> for SocketAddrV4 {
209+
fn from(value: &Osockaddr) -> Self {
211210
// Extract the port
212-
let port = u16::from_be_bytes([self.sa_data[0], self.sa_data[1]]);
211+
let port = u16::from_be_bytes([value.sa_data[0], value.sa_data[1]]);
213212

214213
// Extract the IP address
215214
let ip = Ipv4Addr::new(
216-
self.sa_data[2],
217-
self.sa_data[3],
218-
self.sa_data[4],
219-
self.sa_data[5],
215+
value.sa_data[2],
216+
value.sa_data[3],
217+
value.sa_data[4],
218+
value.sa_data[5],
220219
);
221220

222-
Some(SocketAddrV4::new(ip, port))
221+
Self::new(ip, port)
223222
}
223+
}
224+
225+
impl From<&SocketAddr> for Osockaddr {
226+
fn from(value: &SocketAddr) -> Self {
227+
match value {
228+
SocketAddr::V4(v) => Self::from(v),
229+
SocketAddr::V6(_) => unimplemented!(),
230+
}
231+
}
232+
}
233+
234+
impl From<&SocketAddrV4> for Osockaddr {
235+
fn from(value: &SocketAddrV4) -> Self {
236+
let ip = value.ip().to_string();
237+
let port = value.port();
238+
// TODO use as.bytes()
224239

225-
/// Creates a new `sa_data` array from the given IP address and port.
226-
///
227-
/// # Arguments
228-
///
229-
/// * `ip` - A string slice representing the IP address (e.g., "192.168.1.1").
230-
/// * `port` - A u16 representing the port number.
231-
///
232-
/// # Returns
233-
///
234-
/// Returns an `Option<[u8; 14]>` containing the packed address if successful,
235-
/// or `None` if the IP address format is invalid.
236-
fn new(ip: &str, port: u16) -> [u8; 14] {
237240
let mut sa_data: [u8; 14] = [0; 14];
238241

239242
let ip_segments: Result<Vec<u8>, _> = ip.split('.').map(|s| s.parse::<u8>()).collect();
@@ -249,7 +252,10 @@ impl Osockaddr {
249252
}
250253
}
251254

252-
sa_data
255+
Self {
256+
sa_family: 0, // TODO use enum
257+
sa_data,
258+
}
253259
}
254260
}
255261

@@ -464,9 +470,7 @@ fn handle_existing_invitation(
464470
output_buffer: &mut String,
465471
res: &mut CtlRes,
466472
) -> Result<(), TalkError> {
467-
let tcp_addr = res.addr.to_socketaddr().ok_or_else(|| {
468-
TalkError::AddressResolutionFailed("Failed to convert address to socket address.".into())
469-
})?;
473+
let tcp_addr = SocketAddrV4::from(&res.addr);
470474

471475
// Establish a TCP connection to the `tcp_addr`. Map any IO errors to `TalkError::IoError`.
472476
let stream = TcpStream::connect(tcp_addr).map_err(TalkError::IoError)?;
@@ -916,6 +920,7 @@ fn send_byte(write_stream: &TcpStream, byte: u8) -> Result<(), io::Error> {
916920
/// # Returns
917921
///
918922
/// A `Result` indicating success or a `TalkError`.
923+
#[allow(clippy::too_many_arguments)]
919924
fn handle_new_invitation(
920925
talkd_addr: SocketAddr,
921926
daemon_port: u16,
@@ -932,7 +937,7 @@ fn handle_new_invitation(
932937
logger.set_state("[Service connection established.]");
933938

934939
// Create the socket address data and set it in the `msg`.
935-
let tcp_data = Osockaddr::new(&socket_addr.ip().to_string(), socket_addr.port());
940+
let tcp_data = Osockaddr::from(&socket_addr).sa_data;
936941

937942
logger.set_state("[Waiting for your party to respond]");
938943

0 commit comments

Comments
 (0)