Skip to content

Commit d918d57

Browse files
jerenslsagudev
andauthored
fix: Clippy warning with no features on linux platform (#406)
* clippy: fix clippy warning with no features on linux platform Signed-off-by: Jerens Lensun <[email protected]> * Update src/platform/unix/mod.rs Co-authored-by: sagudev <[email protected]> Signed-off-by: Jerens Lensun <[email protected]> * cargo: fix the cargo format Signed-off-by: Jerens Lensun <[email protected]> --------- Signed-off-by: Jerens Lensun <[email protected]> Signed-off-by: Jerens Lensun <[email protected]> Co-authored-by: sagudev <[email protected]>
1 parent 299305f commit d918d57

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

src/ipc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub enum IpcError {
4747
impl fmt::Display for IpcError {
4848
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
4949
match *self {
50-
IpcError::Bincode(ref err) => write!(fmt, "bincode error: {}", err),
51-
IpcError::Io(ref err) => write!(fmt, "io error: {}", err),
50+
IpcError::Bincode(ref err) => write!(fmt, "bincode error: {err}"),
51+
IpcError::Io(ref err) => write!(fmt, "io error: {err}"),
5252
IpcError::Disconnected => write!(fmt, "disconnected"),
5353
}
5454
}
@@ -73,7 +73,7 @@ pub enum TryRecvError {
7373
impl fmt::Display for TryRecvError {
7474
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
7575
match *self {
76-
TryRecvError::IpcError(ref err) => write!(fmt, "ipc error: {}", err),
76+
TryRecvError::IpcError(ref err) => write!(fmt, "ipc error: {err}"),
7777
TryRecvError::Empty => write!(fmt, "empty"),
7878
}
7979
}
@@ -673,7 +673,7 @@ impl IpcSelectionResult {
673673
match self {
674674
IpcSelectionResult::MessageReceived(id, message) => (id, message),
675675
IpcSelectionResult::ChannelClosed(id) => {
676-
panic!("IpcSelectionResult::unwrap(): channel {} closed", id)
676+
panic!("IpcSelectionResult::unwrap(): channel {id} closed")
677677
},
678678
}
679679
}

src/platform/unix/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,10 @@ impl OsIpcReceiverSet {
539539
assert!(event.is_readable());
540540

541541
let event_token = event.token();
542-
let poll_entry = self
542+
let poll_entry = *self
543543
.pollfds
544544
.get(&event_token)
545-
.expect("Got event for unknown token.")
546-
.clone();
545+
.expect("Got event for unknown token.");
547546
loop {
548547
match recv(poll_entry.fd, BlockingMode::Nonblocking) {
549548
Ok(ipc_message) => {
@@ -590,10 +589,7 @@ impl OsIpcSelectionResult {
590589
match self {
591590
OsIpcSelectionResult::DataReceived(id, ipc_message) => (id, ipc_message),
592591
OsIpcSelectionResult::ChannelClosed(id) => {
593-
panic!(
594-
"OsIpcSelectionResult::unwrap(): receiver ID {} was closed!",
595-
id
596-
)
592+
panic!("OsIpcSelectionResult::unwrap(): receiver ID {id} was closed!")
597593
},
598594
}
599595
}
@@ -863,6 +859,11 @@ impl Deref for OsIpcSharedMemory {
863859
}
864860

865861
impl OsIpcSharedMemory {
862+
/// # Safety
863+
///
864+
/// This is safe if there is only one reader/writer on the data.
865+
/// User can achieve this by not cloning [`IpcSharedMemory`]
866+
/// and serializing/deserializing only once.
866867
#[inline]
867868
pub unsafe fn deref_mut(&mut self) -> &mut [u8] {
868869
unsafe { slice::from_raw_parts_mut(self.ptr, self.length) }

src/test.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Wait for libc::pid_t {
9393
#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))]
9494
pub fn get_channel_name_arg(which: &str) -> Option<String> {
9595
for arg in env::args() {
96-
let arg_str = &*format!("channel_name-{}:", which);
96+
let arg_str = &*format!("channel_name-{which}:");
9797
if let Some(arg) = arg.strip_prefix(arg_str) {
9898
return Some(arg.to_owned());
9999
}
@@ -110,7 +110,7 @@ pub fn spawn_server(test_name: &str, server_args: &[(&str, &str)]) -> process::C
110110
.args(
111111
server_args
112112
.iter()
113-
.map(|(name, val)| format!("channel_name-{}:{}", name, val)),
113+
.map(|(name, val)| format!("channel_name-{name}:{val}")),
114114
)
115115
.stdin(Stdio::null())
116116
.stdout(Stdio::null())
@@ -131,7 +131,7 @@ fn simple() {
131131
drop(tx);
132132
match rx.recv().unwrap_err() {
133133
ipc::IpcError::Disconnected => (),
134-
e => panic!("expected disconnected error, got {:?}", e),
134+
e => panic!("expected disconnected error, got {e:?}"),
135135
}
136136
}
137137

@@ -288,7 +288,7 @@ fn router_simple_global() {
288288
// Try the same, with a strongly typed route
289289
let message: usize = 42;
290290
let (tx, rx) = ipc::channel().unwrap();
291-
tx.send(message.clone()).unwrap();
291+
tx.send(message).unwrap();
292292

293293
let (callback_fired_sender, callback_fired_receiver) = crossbeam_channel::unbounded::<usize>();
294294
ROUTER.add_typed_route(
@@ -448,7 +448,7 @@ fn router_drops_callbacks_on_cloned_sender_shutdown() {
448448
#[test]
449449
fn router_big_data() {
450450
let person = ("Patrick Walton".to_owned(), 29);
451-
let people: Vec<_> = iter::repeat(person).take(64 * 1024).collect();
451+
let people: Vec<_> = std::iter::repeat_n(person, 64 * 1024).collect();
452452
let (tx, rx) = ipc::channel().unwrap();
453453
let people_for_subthread = people.clone();
454454
let thread = thread::spawn(move || {
@@ -550,19 +550,19 @@ fn try_recv() {
550550
let (tx, rx) = ipc::channel().unwrap();
551551
match rx.try_recv() {
552552
Err(ipc::TryRecvError::Empty) => (),
553-
v => panic!("Expected empty channel err: {:?}", v),
553+
v => panic!("Expected empty channel err: {v:?}"),
554554
}
555555
tx.send(person.clone()).unwrap();
556556
let received_person = rx.try_recv().unwrap();
557557
assert_eq!(person, received_person);
558558
match rx.try_recv() {
559559
Err(ipc::TryRecvError::Empty) => (),
560-
v => panic!("Expected empty channel err: {:?}", v),
560+
v => panic!("Expected empty channel err: {v:?}"),
561561
}
562562
drop(tx);
563563
match rx.try_recv() {
564564
Err(ipc::TryRecvError::IpcError(ipc::IpcError::Disconnected)) => (),
565-
v => panic!("Expected disconnected err: {:?}", v),
565+
v => panic!("Expected disconnected err: {v:?}"),
566566
}
567567
}
568568

@@ -576,7 +576,7 @@ fn try_recv_timeout() {
576576
Err(ipc::TryRecvError::Empty) => {
577577
assert!(start_recv.elapsed() >= Duration::from_millis(500))
578578
},
579-
v => panic!("Expected empty channel err: {:?}", v),
579+
v => panic!("Expected empty channel err: {v:?}"),
580580
}
581581
tx.send(person.clone()).unwrap();
582582
let start_recv = Instant::now();
@@ -588,12 +588,12 @@ fn try_recv_timeout() {
588588
Err(ipc::TryRecvError::Empty) => {
589589
assert!(start_recv.elapsed() >= Duration::from_millis(500))
590590
},
591-
v => panic!("Expected empty channel err: {:?}", v),
591+
v => panic!("Expected empty channel err: {v:?}"),
592592
}
593593
drop(tx);
594594
match rx.try_recv_timeout(timeout) {
595595
Err(ipc::TryRecvError::IpcError(ipc::IpcError::Disconnected)) => (),
596-
v => panic!("Expected disconnected err: {:?}", v),
596+
v => panic!("Expected disconnected err: {v:?}"),
597597
}
598598
}
599599

@@ -651,7 +651,7 @@ fn test_so_linger() {
651651
let val = match receiver.recv() {
652652
Ok(val) => val,
653653
Err(e) => {
654-
panic!("err: `{:?}`", e);
654+
panic!("err: `{e:?}`");
655655
},
656656
};
657657
assert_eq!(val, 42);

0 commit comments

Comments
 (0)