Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub enum IpcError {
impl fmt::Display for IpcError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
IpcError::Bincode(ref err) => write!(fmt, "bincode error: {}", err),
IpcError::Io(ref err) => write!(fmt, "io error: {}", err),
IpcError::Bincode(ref err) => write!(fmt, "bincode error: {err}"),
IpcError::Io(ref err) => write!(fmt, "io error: {err}"),
IpcError::Disconnected => write!(fmt, "disconnected"),
}
}
Expand All @@ -73,7 +73,7 @@ pub enum TryRecvError {
impl fmt::Display for TryRecvError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
TryRecvError::IpcError(ref err) => write!(fmt, "ipc error: {}", err),
TryRecvError::IpcError(ref err) => write!(fmt, "ipc error: {err}"),
TryRecvError::Empty => write!(fmt, "empty"),
}
}
Expand Down Expand Up @@ -673,7 +673,7 @@ impl IpcSelectionResult {
match self {
IpcSelectionResult::MessageReceived(id, message) => (id, message),
IpcSelectionResult::ChannelClosed(id) => {
panic!("IpcSelectionResult::unwrap(): channel {} closed", id)
panic!("IpcSelectionResult::unwrap(): channel {id} closed")
},
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,10 @@ impl OsIpcReceiverSet {
assert!(event.is_readable());

let event_token = event.token();
let poll_entry = self
let poll_entry = *self
.pollfds
.get(&event_token)
.expect("Got event for unknown token.")
.clone();
.expect("Got event for unknown token.");
loop {
match recv(poll_entry.fd, BlockingMode::Nonblocking) {
Ok(ipc_message) => {
Expand Down Expand Up @@ -590,10 +589,7 @@ impl OsIpcSelectionResult {
match self {
OsIpcSelectionResult::DataReceived(id, ipc_message) => (id, ipc_message),
OsIpcSelectionResult::ChannelClosed(id) => {
panic!(
"OsIpcSelectionResult::unwrap(): receiver ID {} was closed!",
id
)
panic!("OsIpcSelectionResult::unwrap(): receiver ID {id} was closed!")
},
}
}
Expand Down Expand Up @@ -863,6 +859,11 @@ impl Deref for OsIpcSharedMemory {
}

impl OsIpcSharedMemory {
/// # Safety
///
/// This is safe if there is only one reader/writer on the data.
/// User can achieve this by not cloning [`IpcSharedMemory`]
/// and serializing/deserializing only once.
#[inline]
pub unsafe fn deref_mut(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.ptr, self.length) }
Expand Down
24 changes: 12 additions & 12 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Wait for libc::pid_t {
#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))]
pub fn get_channel_name_arg(which: &str) -> Option<String> {
for arg in env::args() {
let arg_str = &*format!("channel_name-{}:", which);
let arg_str = &*format!("channel_name-{which}:");
if let Some(arg) = arg.strip_prefix(arg_str) {
return Some(arg.to_owned());
}
Expand All @@ -110,7 +110,7 @@ pub fn spawn_server(test_name: &str, server_args: &[(&str, &str)]) -> process::C
.args(
server_args
.iter()
.map(|(name, val)| format!("channel_name-{}:{}", name, val)),
.map(|(name, val)| format!("channel_name-{name}:{val}")),
)
.stdin(Stdio::null())
.stdout(Stdio::null())
Expand All @@ -131,7 +131,7 @@ fn simple() {
drop(tx);
match rx.recv().unwrap_err() {
ipc::IpcError::Disconnected => (),
e => panic!("expected disconnected error, got {:?}", e),
e => panic!("expected disconnected error, got {e:?}"),
}
}

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

let (callback_fired_sender, callback_fired_receiver) = crossbeam_channel::unbounded::<usize>();
ROUTER.add_typed_route(
Expand Down Expand Up @@ -448,7 +448,7 @@ fn router_drops_callbacks_on_cloned_sender_shutdown() {
#[test]
fn router_big_data() {
let person = ("Patrick Walton".to_owned(), 29);
let people: Vec<_> = iter::repeat(person).take(64 * 1024).collect();
let people: Vec<_> = std::iter::repeat_n(person, 64 * 1024).collect();
let (tx, rx) = ipc::channel().unwrap();
let people_for_subthread = people.clone();
let thread = thread::spawn(move || {
Expand Down Expand Up @@ -550,19 +550,19 @@ fn try_recv() {
let (tx, rx) = ipc::channel().unwrap();
match rx.try_recv() {
Err(ipc::TryRecvError::Empty) => (),
v => panic!("Expected empty channel err: {:?}", v),
v => panic!("Expected empty channel err: {v:?}"),
}
tx.send(person.clone()).unwrap();
let received_person = rx.try_recv().unwrap();
assert_eq!(person, received_person);
match rx.try_recv() {
Err(ipc::TryRecvError::Empty) => (),
v => panic!("Expected empty channel err: {:?}", v),
v => panic!("Expected empty channel err: {v:?}"),
}
drop(tx);
match rx.try_recv() {
Err(ipc::TryRecvError::IpcError(ipc::IpcError::Disconnected)) => (),
v => panic!("Expected disconnected err: {:?}", v),
v => panic!("Expected disconnected err: {v:?}"),
}
}

Expand All @@ -576,7 +576,7 @@ fn try_recv_timeout() {
Err(ipc::TryRecvError::Empty) => {
assert!(start_recv.elapsed() >= Duration::from_millis(500))
},
v => panic!("Expected empty channel err: {:?}", v),
v => panic!("Expected empty channel err: {v:?}"),
}
tx.send(person.clone()).unwrap();
let start_recv = Instant::now();
Expand All @@ -588,12 +588,12 @@ fn try_recv_timeout() {
Err(ipc::TryRecvError::Empty) => {
assert!(start_recv.elapsed() >= Duration::from_millis(500))
},
v => panic!("Expected empty channel err: {:?}", v),
v => panic!("Expected empty channel err: {v:?}"),
}
drop(tx);
match rx.try_recv_timeout(timeout) {
Err(ipc::TryRecvError::IpcError(ipc::IpcError::Disconnected)) => (),
v => panic!("Expected disconnected err: {:?}", v),
v => panic!("Expected disconnected err: {v:?}"),
}
}

Expand Down Expand Up @@ -651,7 +651,7 @@ fn test_so_linger() {
let val = match receiver.recv() {
Ok(val) => val,
Err(e) => {
panic!("err: `{:?}`", e);
panic!("err: `{e:?}`");
},
};
assert_eq!(val, 42);
Expand Down