Skip to content

Commit ab418ba

Browse files
committed
Fix clippy::new_ret_no_self
1 parent f827d7b commit ab418ba

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
@@ -199,35 +199,38 @@ pub struct Osockaddr {
199199
pub sa_data: [u8; 14],
200200
}
201201

202-
impl Osockaddr {
203-
// Converts the packed address structure into a SocketAddrV4
204-
pub fn to_socketaddr(&self) -> Option<SocketAddrV4> {
202+
impl From<&Osockaddr> for SocketAddrV4 {
203+
fn from(value: &Osockaddr) -> Self {
205204
// Extract the port
206-
let port = u16::from_be_bytes([self.sa_data[0], self.sa_data[1]]);
205+
let port = u16::from_be_bytes([value.sa_data[0], value.sa_data[1]]);
207206

208207
// Extract the IP address
209208
let ip = Ipv4Addr::new(
210-
self.sa_data[2],
211-
self.sa_data[3],
212-
self.sa_data[4],
213-
self.sa_data[5],
209+
value.sa_data[2],
210+
value.sa_data[3],
211+
value.sa_data[4],
212+
value.sa_data[5],
214213
);
215214

216-
Some(SocketAddrV4::new(ip, port))
215+
Self::new(ip, port)
217216
}
217+
}
218+
219+
impl From<&SocketAddr> for Osockaddr {
220+
fn from(value: &SocketAddr) -> Self {
221+
match value {
222+
SocketAddr::V4(v) => Self::from(v),
223+
SocketAddr::V6(_) => unimplemented!(),
224+
}
225+
}
226+
}
227+
228+
impl From<&SocketAddrV4> for Osockaddr {
229+
fn from(value: &SocketAddrV4) -> Self {
230+
let ip = value.ip().to_string();
231+
let port = value.port();
232+
// TODO use as.bytes()
218233

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

233236
let ip_segments: Result<Vec<u8>, _> = ip.split('.').map(|s| s.parse::<u8>()).collect();
@@ -243,7 +246,10 @@ impl Osockaddr {
243246
}
244247
}
245248

246-
sa_data
249+
Self {
250+
sa_family: 0, // TODO use enum
251+
sa_data,
252+
}
247253
}
248254
}
249255

@@ -458,9 +464,7 @@ fn handle_existing_invitation(
458464
output_buffer: &mut String,
459465
res: &mut CtlRes,
460466
) -> Result<(), TalkError> {
461-
let tcp_addr = res.addr.to_socketaddr().ok_or_else(|| {
462-
TalkError::AddressResolutionFailed("Failed to convert address to socket address.".into())
463-
})?;
467+
let tcp_addr = SocketAddrV4::from(&res.addr);
464468

465469
// Establish a TCP connection to the `tcp_addr`. Map any IO errors to `TalkError::IoError`.
466470
let stream = TcpStream::connect(tcp_addr).map_err(TalkError::IoError)?;
@@ -903,6 +907,7 @@ fn send_byte(write_stream: &TcpStream, byte: u8) -> Result<(), io::Error> {
903907
/// # Returns
904908
///
905909
/// A `Result` indicating success or a `TalkError`.
910+
#[allow(clippy::too_many_arguments)]
906911
fn handle_new_invitation(
907912
talkd_addr: SocketAddr,
908913
daemon_port: u16,
@@ -919,7 +924,7 @@ fn handle_new_invitation(
919924
logger.set_state("[Service connection established.]");
920925

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

924929
logger.set_state("[Waiting for your party to respond]");
925930

0 commit comments

Comments
 (0)