Skip to content

Commit

Permalink
Fix clippy warning and keep 1.56 MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassy343 committed Jul 10, 2022
1 parent 2169f2c commit e58f11c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,34 +973,40 @@ impl<T> Channel<T> {
}

#[inline(always)]
unsafe fn message_mut(&self) -> &mut MaybeUninit<T> {
unsafe fn with_message_mut<F>(&self, op: F)
where
F: FnOnce(&mut MaybeUninit<T>),
{
#[cfg(loom)]
{
self.message.with_mut(|ptr| &mut *ptr)
self.message.with_mut(|ptr| op(&mut *ptr))
}

#[cfg(not(loom))]
{
&mut *self.message.get()
op(&mut *self.message.get())
}
}

#[inline(always)]
unsafe fn waker_mut(&self) -> &mut MaybeUninit<ReceiverWaker> {
unsafe fn with_waker_mut<F>(&self, op: F)
where
F: FnOnce(&mut MaybeUninit<ReceiverWaker>),
{
#[cfg(loom)]
{
self.waker.with_mut(|ptr| &mut *ptr)
self.waker.with_mut(|ptr| op(&mut *ptr))
}

#[cfg(not(loom))]
{
&mut *self.waker.get()
op(&mut *self.waker.get())
}
}

#[inline(always)]
unsafe fn write_message(&self, message: T) {
self.message_mut().as_mut_ptr().write(message);
self.with_message_mut(|slot| slot.as_mut_ptr().write(message));
}

#[inline(always)]
Expand All @@ -1018,13 +1024,13 @@ impl<T> Channel<T> {

#[inline(always)]
unsafe fn drop_message(&self) {
self.message_mut().assume_init_drop();
self.with_message_mut(|slot| ptr::drop_in_place(slot.as_mut_ptr()));
}

#[cfg(any(feature = "std", feature = "async"))]
#[inline(always)]
unsafe fn write_waker(&self, waker: ReceiverWaker) {
self.waker_mut().as_mut_ptr().write(waker);
self.with_waker_mut(|slot| slot.as_mut_ptr().write(waker));
}

#[inline(always)]
Expand All @@ -1043,7 +1049,7 @@ impl<T> Channel<T> {
#[cfg(any(feature = "std", feature = "async"))]
#[inline(always)]
unsafe fn drop_waker(&self) {
self.waker_mut().assume_init_drop();
self.with_waker_mut(|slot| ptr::drop_in_place(slot.as_mut_ptr()));
}

#[cfg(feature = "async")]
Expand Down

0 comments on commit e58f11c

Please sign in to comment.