Remove mpsc::Sender::downgrade()

This commit is contained in:
Nikolay Kim 2024-08-19 16:02:44 +05:00
parent 7445f7b45a
commit a1c4b13500
3 changed files with 6 additions and 52 deletions

View file

@ -1,5 +1,9 @@
# Changes
## [2.4.0] - 2024-xx-xx
* Remove mpsc::Sender::downgrade()
## [2.3.0] - 2024-08-19
* Allow to send clonable value via `Condition`

View file

@ -1,5 +1,4 @@
//! Custom cell impl
use std::{cell::UnsafeCell, fmt, rc::Rc, rc::Weak};
use std::{cell::UnsafeCell, fmt, rc::Rc};
pub(super) struct Cell<T> {
inner: Rc<UnsafeCell<T>>,
@ -38,29 +37,4 @@ impl<T> Cell<T> {
pub(super) fn get_mut(&self) -> &mut T {
unsafe { &mut *self.inner.as_ref().get() }
}
pub(super) fn downgrade(&self) -> WeakCell<T> {
WeakCell {
inner: Rc::downgrade(&self.inner),
}
}
}
#[derive(Debug)]
pub(super) struct WeakCell<T> {
inner: Weak<UnsafeCell<T>>,
}
impl<T> Clone for WeakCell<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<T> WeakCell<T> {
pub(super) fn upgrade(&self) -> Option<Cell<T>> {
self.inner.upgrade().map(|inner| Cell { inner })
}
}

View file

@ -6,7 +6,7 @@ use std::{fmt, panic::UnwindSafe, pin::Pin, task::Context, task::Poll};
use futures_core::{FusedStream, Stream};
use futures_sink::Sink;
use super::cell::{Cell, WeakCell};
use super::cell::Cell;
use crate::task::LocalWaker;
/// Creates a unbounded in-memory channel with buffered storage.
@ -66,13 +66,6 @@ impl<T> Sender<T> {
pub fn is_closed(&self) -> bool {
self.shared.strong_count() == 1 || !self.shared.get_ref().has_receiver
}
/// Returns downgraded sender
pub fn downgrade(self) -> WeakSender<T> {
WeakSender {
shared: self.shared.downgrade(),
}
}
}
impl<T> Clone for Sender<T> {
@ -126,19 +119,6 @@ impl<T> Drop for Sender<T> {
}
}
#[derive(Debug)]
/// Weak sender type
pub struct WeakSender<T> {
shared: WeakCell<Shared<T>>,
}
impl<T> WeakSender<T> {
/// Upgrade to `Sender<T>`
pub fn upgrade(&self) -> Option<Sender<T>> {
self.shared.upgrade().map(|shared| Sender { shared })
}
}
/// The receiving end of a channel which implements the `Stream` trait.
///
/// This is created by the `channel` function.
@ -282,10 +262,6 @@ mod tests {
tx.close();
assert_eq!(stream_recv(&mut rx).await, None);
let (tx, _rx) = channel::<String>();
let weak_tx = tx.downgrade();
assert!(weak_tx.upgrade().is_some());
let (tx, rx) = channel();
tx.send("test").unwrap();
drop(rx);