Skip to content

Commit 64e76e5

Browse files
authored
chore: Fix clippy warning on force-inprocess feature (#411)
* chore: Fix clippy error on force inprocess feature Signed-off-by: Jerens Lensun <[email protected]> * chore: Fix format issue on inprocess/mod.rs Signed-off-by: Jerens Lensun <[email protected]> * script_bindings(python): Add comment Safety on unsafe OsIpcSharedMemory Signed-off-by: Jerens Lensun <[email protected]> --------- Signed-off-by: Jerens Lensun <[email protected]>
1 parent eb0bbdd commit 64e76e5

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/platform/inprocess/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ use std::error::Error as StdError;
1717
use std::fmt::{self, Debug, Formatter};
1818
use std::io;
1919
use std::ops::{Deref, RangeFrom};
20+
use std::ptr::eq;
2021
use std::slice;
2122
use std::sync::{Arc, LazyLock, Mutex};
2223
use std::time::Duration;
23-
use std::usize;
24+
use usize;
2425
use uuid::Uuid;
2526

2627
#[derive(Clone)]
@@ -34,7 +35,7 @@ impl ServerRecord {
3435
fn new(sender: OsIpcSender) -> ServerRecord {
3536
let (tx, rx) = crossbeam_channel::unbounded::<bool>();
3637
ServerRecord {
37-
sender: sender,
38+
sender,
3839
conn_sender: tx,
3940
conn_receiver: rx,
4041
}
@@ -128,7 +129,10 @@ pub struct OsIpcSender {
128129

129130
impl PartialEq for OsIpcSender {
130131
fn eq(&self, other: &OsIpcSender) -> bool {
131-
&*self.sender.borrow() as *const _ == &*other.sender.borrow() as *const _
132+
eq(
133+
&*self.sender.borrow() as *const _,
134+
&*other.sender.borrow() as *const _,
135+
)
132136
}
133137
}
134138

@@ -157,11 +161,10 @@ impl OsIpcSender {
157161
) -> Result<(), ChannelError> {
158162
let os_ipc_channels = ports.into_iter().map(OsOpaqueIpcChannel::new).collect();
159163
let ipc_message = IpcMessage::new(data.to_vec(), os_ipc_channels, shared_memory_regions);
160-
Ok(self
161-
.sender
164+
self.sender
162165
.borrow()
163166
.send(ChannelMessage(ipc_message))
164-
.map_err(|_| ChannelError::BrokenPipeError)?)
167+
.map_err(|_| ChannelError::BrokenPipeError)
165168
}
166169
}
167170

@@ -204,12 +207,12 @@ impl OsIpcReceiverSet {
204207

205208
let mut select = Select::new();
206209
for r in &borrows {
207-
select.recv(&r);
210+
select.recv(r);
208211
}
209212
let res = select.select();
210213
let receiver_index = res.index();
211214
let receiver_id = self.receiver_ids[receiver_index];
212-
if let Ok(ChannelMessage(ipc_message)) = res.recv(&borrows[receiver_index as usize]) {
215+
if let Ok(ChannelMessage(ipc_message)) = res.recv(&borrows[receiver_index]) {
213216
return Ok(vec![OsIpcSelectionResult::DataReceived(
214217
receiver_id,
215218
ipc_message,
@@ -234,10 +237,7 @@ impl OsIpcSelectionResult {
234237
match self {
235238
OsIpcSelectionResult::DataReceived(id, ipc_message) => (id, ipc_message),
236239
OsIpcSelectionResult::ChannelClosed(id) => {
237-
panic!(
238-
"OsIpcSelectionResult::unwrap(): receiver ID {} was closed!",
239-
id
240-
)
240+
panic!("OsIpcSelectionResult::unwrap(): receiver ID {id} was closed!")
241241
},
242242
}
243243
}
@@ -260,7 +260,7 @@ impl OsIpcOneShotServer {
260260
.insert(name.clone(), record);
261261
Ok((
262262
OsIpcOneShotServer {
263-
receiver: receiver,
263+
receiver,
264264
name: name.clone(),
265265
},
266266
name.clone(),
@@ -358,6 +358,11 @@ impl Deref for OsIpcSharedMemory {
358358
}
359359

360360
impl OsIpcSharedMemory {
361+
/// # Safety
362+
///
363+
/// This is safe if there is only one reader/writer on the data.
364+
/// User can achieve this by not cloning [`IpcSharedMemory`]
365+
/// and serializing/deserializing only once.
361366
#[inline]
362367
pub unsafe fn deref_mut(&mut self) -> &mut [u8] {
363368
if self.ptr.is_null() {
@@ -372,7 +377,7 @@ impl OsIpcSharedMemory {
372377
let mut v = Arc::new(vec![byte; length]);
373378
OsIpcSharedMemory {
374379
ptr: Arc::get_mut(&mut v).unwrap().as_mut_ptr(),
375-
length: length,
380+
length,
376381
data: v,
377382
}
378383
}
@@ -457,9 +462,7 @@ impl From<ChannelError> for io::Error {
457462
io::ErrorKind::BrokenPipe,
458463
"crossbeam-channel receiver closed",
459464
),
460-
ChannelError::UnknownError => {
461-
io::Error::new(io::ErrorKind::Other, "Other crossbeam-channel error")
462-
},
465+
ChannelError::UnknownError => io::Error::other("Other crossbeam-channel error"),
463466
}
464467
}
465468
}

0 commit comments

Comments
 (0)