diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2023-02-15 20:20:31 +0100 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2023-02-15 20:20:31 +0100 |
commit | 9d8cc3ef6e7149202a827da51ff4d66cc08f963b (patch) | |
tree | e05d642f5ac3017af8055f2b63cb9b03eee6d460 | |
parent | 25fd1f2d5a3f0940a9494685c88899ee68320d52 (diff) | |
download | futures-channel-9d8cc3ef6e7149202a827da51ff4d66cc08f963b.tar.gz |
Upgrade futures-channel to 0.3.26
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update rust/crates/futures-channel
For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
Test: TreeHugger
Change-Id: I19007d4967d4a81b7e5a56808ea712f4f492c478
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 16 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | src/mpsc/mod.rs | 71 | ||||
-rw-r--r-- | src/mpsc/queue.rs | 2 | ||||
-rw-r--r-- | src/oneshot.rs | 4 | ||||
-rw-r--r-- | tests/mpsc-size_hint.rs | 40 |
9 files changed, 128 insertions, 29 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 662e5e9..3fade60 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "77d82198c5afd04af3e760a6aa50b7e875289fc3" + "sha1": "5e3693a350f96244151081d2c030208cd15f9572" }, "path_in_vcs": "futures-channel" }
\ No newline at end of file @@ -46,7 +46,7 @@ rust_test { host_supported: true, crate_name: "futures_channel", cargo_env_compat: true, - cargo_pkg_version: "0.3.25", + cargo_pkg_version: "0.3.26", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -73,7 +73,7 @@ rust_defaults { name: "futures-channel_test_defaults", crate_name: "futures_channel", cargo_env_compat: true, - cargo_pkg_version: "0.3.25", + cargo_pkg_version: "0.3.26", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -114,6 +114,16 @@ rust_test { } rust_test { + name: "futures-channel_test_tests_mpsc-size_hint", + defaults: ["futures-channel_test_defaults"], + host_supported: true, + srcs: ["tests/mpsc-size_hint.rs"], + test_options: { + unit_test: true, + }, +} + +rust_test { name: "futures-channel_test_tests_mpsc", defaults: ["futures-channel_test_defaults"], host_supported: true, @@ -138,7 +148,7 @@ rust_library { host_supported: true, crate_name: "futures_channel", cargo_env_compat: true, - cargo_pkg_version: "0.3.25", + cargo_pkg_version: "0.3.26", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.45" name = "futures-channel" -version = "0.3.25" +version = "0.3.26" description = """ Channels for asynchronous communication using futures-rs. """ @@ -30,11 +30,11 @@ rustdoc-args = [ ] [dependencies.futures-core] -version = "0.3.25" +version = "0.3.26" default-features = false [dependencies.futures-sink] -version = "0.3.25" +version = "0.3.26" optional = true default-features = false diff --git a/Cargo.toml.orig b/Cargo.toml.orig index eef8684..753fd46 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" edition = "2018" rust-version = "1.45" license = "MIT OR Apache-2.0" @@ -22,8 +22,8 @@ unstable = [] cfg-target-has-atomic = [] [dependencies] -futures-core = { path = "../futures-core", version = "0.3.25", default-features = false } -futures-sink = { path = "../futures-sink", version = "0.3.25", default-features = false, optional = true } +futures-core = { path = "../futures-core", version = "0.3.26", default-features = false } +futures-sink = { path = "../futures-sink", version = "0.3.26", default-features = false, optional = true } [dev-dependencies] futures = { path = "../futures", default-features = true } @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/futures-channel/futures-channel-0.3.25.crate" + value: "https://static.crates.io/crates/futures-channel/futures-channel-0.3.26.crate" } - version: "0.3.25" + version: "0.3.26" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 12 + year: 2023 + month: 2 + day: 15 } } diff --git a/src/mpsc/mod.rs b/src/mpsc/mod.rs index 44834b7..cf45fe7 100644 --- a/src/mpsc/mod.rs +++ b/src/mpsc/mod.rs @@ -94,13 +94,11 @@ mod queue; #[cfg(feature = "sink")] mod sink_impl; -#[derive(Debug)] struct UnboundedSenderInner<T> { // Channel state shared between the sender and receiver. inner: Arc<UnboundedInner<T>>, } -#[derive(Debug)] struct BoundedSenderInner<T> { // Channel state shared between the sender and receiver. inner: Arc<BoundedInner<T>>, @@ -122,13 +120,11 @@ impl<T> Unpin for BoundedSenderInner<T> {} /// The transmission end of a bounded mpsc channel. /// /// This value is created by the [`channel`](channel) function. -#[derive(Debug)] pub struct Sender<T>(Option<BoundedSenderInner<T>>); /// The transmission end of an unbounded mpsc channel. /// /// This value is created by the [`unbounded`](unbounded) function. -#[derive(Debug)] pub struct UnboundedSender<T>(Option<UnboundedSenderInner<T>>); trait AssertKinds: Send + Sync + Clone {} @@ -137,7 +133,6 @@ impl AssertKinds for UnboundedSender<u32> {} /// The receiving end of a bounded mpsc channel. /// /// This value is created by the [`channel`](channel) function. -#[derive(Debug)] pub struct Receiver<T> { inner: Option<Arc<BoundedInner<T>>>, } @@ -145,7 +140,6 @@ pub struct Receiver<T> { /// The receiving end of an unbounded mpsc channel. /// /// This value is created by the [`unbounded`](unbounded) function. -#[derive(Debug)] pub struct UnboundedReceiver<T> { inner: Option<Arc<UnboundedInner<T>>>, } @@ -261,7 +255,6 @@ impl fmt::Display for TryRecvError { impl std::error::Error for TryRecvError {} -#[derive(Debug)] struct UnboundedInner<T> { // Internal channel state. Consists of the number of messages stored in the // channel as well as a flag signalling that the channel is closed. @@ -277,7 +270,6 @@ struct UnboundedInner<T> { recv_task: AtomicWaker, } -#[derive(Debug)] struct BoundedInner<T> { // Max buffer size of the channel. If `None` then the channel is unbounded. buffer: usize, @@ -300,7 +292,7 @@ struct BoundedInner<T> { } // Struct representation of `Inner::state`. -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] struct State { // `true` when the channel is open is_open: bool, @@ -324,7 +316,6 @@ const MAX_CAPACITY: usize = !(OPEN_MASK); const MAX_BUFFER: usize = MAX_CAPACITY >> 1; // Sent to the consumer to wake up blocked producers -#[derive(Debug)] struct SenderTask { task: Option<Waker>, is_parked: bool, @@ -947,6 +938,18 @@ impl<T> Drop for BoundedSenderInner<T> { } } +impl<T> fmt::Debug for Sender<T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Sender").field("closed", &self.is_closed()).finish() + } +} + +impl<T> fmt::Debug for UnboundedSender<T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("UnboundedSender").field("closed", &self.is_closed()).finish() + } +} + /* * * ===== impl Receiver ===== @@ -1075,6 +1078,14 @@ impl<T> Stream for Receiver<T> { } } } + + fn size_hint(&self) -> (usize, Option<usize>) { + if let Some(inner) = &self.inner { + decode_state(inner.state.load(SeqCst)).size_hint() + } else { + (0, Some(0)) + } + } } impl<T> Drop for Receiver<T> { @@ -1107,6 +1118,18 @@ impl<T> Drop for Receiver<T> { } } +impl<T> fmt::Debug for Receiver<T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let closed = if let Some(ref inner) = self.inner { + decode_state(inner.state.load(SeqCst)).is_closed() + } else { + false + }; + + f.debug_struct("Receiver").field("closed", &closed).finish() + } +} + impl<T> UnboundedReceiver<T> { /// Closes the receiving half of a channel, without dropping it. /// @@ -1207,6 +1230,14 @@ impl<T> Stream for UnboundedReceiver<T> { } } } + + fn size_hint(&self) -> (usize, Option<usize>) { + if let Some(inner) = &self.inner { + decode_state(inner.state.load(SeqCst)).size_hint() + } else { + (0, Some(0)) + } + } } impl<T> Drop for UnboundedReceiver<T> { @@ -1239,6 +1270,18 @@ impl<T> Drop for UnboundedReceiver<T> { } } +impl<T> fmt::Debug for UnboundedReceiver<T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let closed = if let Some(ref inner) = self.inner { + decode_state(inner.state.load(SeqCst)).is_closed() + } else { + false + }; + + f.debug_struct("Receiver").field("closed", &closed).finish() + } +} + /* * * ===== impl Inner ===== @@ -1285,6 +1328,14 @@ impl State { fn is_closed(&self) -> bool { !self.is_open && self.num_messages == 0 } + + fn size_hint(&self) -> (usize, Option<usize>) { + if self.is_open { + (self.num_messages, None) + } else { + (self.num_messages, Some(self.num_messages)) + } + } } /* diff --git a/src/mpsc/queue.rs b/src/mpsc/queue.rs index 57dc7f5..02ec633 100644 --- a/src/mpsc/queue.rs +++ b/src/mpsc/queue.rs @@ -61,7 +61,6 @@ pub(super) enum PopResult<T> { Inconsistent, } -#[derive(Debug)] struct Node<T> { next: AtomicPtr<Self>, value: Option<T>, @@ -70,7 +69,6 @@ struct Node<T> { /// The multi-producer single-consumer structure. This is not cloneable, but it /// may be safely shared so long as it is guaranteed that there is only one /// popper at a time (many pushers are allowed). -#[derive(Debug)] pub(super) struct Queue<T> { head: AtomicPtr<Node<T>>, tail: UnsafeCell<*mut Node<T>>, diff --git a/src/oneshot.rs b/src/oneshot.rs index 5af651b..70449f4 100644 --- a/src/oneshot.rs +++ b/src/oneshot.rs @@ -390,7 +390,7 @@ impl<T> Drop for Sender<T> { } } -impl<T: fmt::Debug> fmt::Debug for Sender<T> { +impl<T> fmt::Debug for Sender<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Sender").field("complete", &self.inner.complete).finish() } @@ -481,7 +481,7 @@ impl<T> Drop for Receiver<T> { } } -impl<T: fmt::Debug> fmt::Debug for Receiver<T> { +impl<T> fmt::Debug for Receiver<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Receiver").field("complete", &self.inner.complete).finish() } diff --git a/tests/mpsc-size_hint.rs b/tests/mpsc-size_hint.rs new file mode 100644 index 0000000..d9cdaa3 --- /dev/null +++ b/tests/mpsc-size_hint.rs @@ -0,0 +1,40 @@ +use futures::channel::mpsc; +use futures::stream::Stream; + +#[test] +fn unbounded_size_hint() { + let (tx, mut rx) = mpsc::unbounded::<u32>(); + assert_eq!((0, None), rx.size_hint()); + tx.unbounded_send(1).unwrap(); + assert_eq!((1, None), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, None), rx.size_hint()); + tx.unbounded_send(2).unwrap(); + tx.unbounded_send(3).unwrap(); + assert_eq!((2, None), rx.size_hint()); + drop(tx); + assert_eq!((2, Some(2)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((1, Some(1)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, Some(0)), rx.size_hint()); +} + +#[test] +fn channel_size_hint() { + let (mut tx, mut rx) = mpsc::channel::<u32>(10); + assert_eq!((0, None), rx.size_hint()); + tx.try_send(1).unwrap(); + assert_eq!((1, None), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, None), rx.size_hint()); + tx.try_send(2).unwrap(); + tx.try_send(3).unwrap(); + assert_eq!((2, None), rx.size_hint()); + drop(tx); + assert_eq!((2, Some(2)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((1, Some(1)), rx.size_hint()); + rx.try_next().unwrap().unwrap(); + assert_eq!((0, Some(0)), rx.size_hint()); +} |