Explicitly drop non consumed items
This commit is contained in:
parent
7c723d2bfd
commit
a247fa4f2c
@ -41,6 +41,7 @@ use core::cell::UnsafeCell;
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
|
use core::ptr;
|
||||||
use core::task::Context;
|
use core::task::Context;
|
||||||
use core::task::Poll;
|
use core::task::Poll;
|
||||||
use core::task::Waker;
|
use core::task::Waker;
|
||||||
@ -416,6 +417,16 @@ impl<T, const N: usize> ChannelState<T, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, const N: usize> Drop for ChannelState<T, N> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
while self.read_pos != self.write_pos || self.full {
|
||||||
|
self.full = false;
|
||||||
|
unsafe { ptr::drop_in_place(self.buf[self.read_pos].as_mut_ptr()) };
|
||||||
|
self.read_pos = (self.read_pos + 1) % N;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A a bounded mpsc channel for communicating between asynchronous tasks
|
/// A a bounded mpsc channel for communicating between asynchronous tasks
|
||||||
/// with backpressure.
|
/// with backpressure.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user