repo
stringclasses
7 values
lang
stringclasses
2 values
aspect
stringclasses
7 values
file
stringlengths
5
48
content
stringlengths
283
144k
tokio
rust
async_runtime
stream_fused.rs
use futures_core::FusedStream; use tokio_stream::{Stream, StreamExt, StreamNotifyClose}; use std::pin::Pin; use std::task::{Context, Poll}; struct EndOnce { ended: bool, } impl Stream for EndOnce { type Item = (); fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> ...
tokio
rust
async_runtime
stream_peekable.rs
use tokio_stream::{self as stream, Stream, StreamExt}; use tokio_test::{assert_pending, assert_ready, task}; use std::pin::Pin; use std::task::{Context, Poll}; #[tokio::test] async fn size_hint_without_peek() { let mut s = stream::iter(vec![1, 2, 3]).peekable(); assert_eq!(s.size_hint(), (3, Some(3))); s....
tokio
rust
async_runtime
stream_chain.rs
use tokio_stream::{self as stream, Stream, StreamExt}; use tokio_test::{assert_pending, assert_ready, task}; mod support { pub(crate) mod mpsc; } use support::mpsc; use tokio_stream::adapters::Chain; #[tokio::test] async fn basic_usage() { let one = stream::iter(vec![1, 2, 3]); let two = stream::iter(vec...
tokio
rust
async_runtime
join_set_stream.rs
#![cfg(feature = "rt")] use futures::{Stream, StreamExt}; use std::collections::HashSet; use tokio::task::JoinSet; use tokio_stream::wrappers::JoinSetStream; #[tokio::test] async fn size_hint_stream() { let set: JoinSet<_> = (0..2).map(|i| async move { i }).collect(); let mut stream = JoinSetStream::new(set);...
tokio
rust
async_runtime
stream_panic.rs
#![warn(rust_2018_idioms)] #![cfg(all(feature = "time", not(target_os = "wasi")))] // Wasi does not support panic recovery #![cfg(panic = "unwind")] use parking_lot::Mutex; use std::error::Error; use std::panic; use std::sync::Arc; use tokio::time::Duration; use tokio_stream::{self as stream, StreamExt}; fn test_pani...
tokio
rust
async_runtime
stream_chunks_timeout.rs
#![warn(rust_2018_idioms)] use futures::FutureExt; use std::error::Error; use tokio::time; use tokio::time::Duration; use tokio_stream::{self as stream, StreamExt}; use tokio_test::assert_pending; use tokio_test::task; #[tokio::test(start_paused = true)] async fn stream_chunks_remainder() -> Result<(), Box<dyn Error>...
tokio
rust
async_runtime
stream_merge.rs
use tokio_stream::{self as stream, Stream, StreamExt}; use tokio_test::task; use tokio_test::{assert_pending, assert_ready}; mod support { pub(crate) mod mpsc; } use support::mpsc; #[tokio::test] async fn merge_sync_streams() { let mut s = stream::iter(vec![0, 2, 4, 6]).merge(stream::iter(vec![1, 3, 5])); ...
tokio
rust
async_runtime
stream_accessors.rs
use std::pin::Pin; use tokio_stream::{self as stream, Iter, StreamExt}; fn base() -> Iter<std::vec::IntoIter<i32>> { stream::iter(vec![1, 2, 3]) } #[tokio::test] async fn map_accessors() { let mut map = base().map(|x| x * 2); let _: &Iter<_> = map.get_ref(); let _: &mut Iter<_> = map.get_mut(); ...
tokio
rust
async_runtime
stream_fuse.rs
use futures_core::FusedStream; use tokio_stream::{Stream, StreamExt}; use std::pin::Pin; use std::task::{Context, Poll}; // a stream which alternates between Some and None struct Alternate { state: i32, } impl Stream for Alternate { type Item = i32; fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Conte...
tokio
rust
async_runtime
stream_timeout.rs
#![cfg(all(feature = "time", feature = "sync", feature = "io-util"))] use tokio::time::{self, sleep, Duration}; use tokio_stream::StreamExt; use tokio_test::*; use futures::stream; async fn maybe_sleep(idx: i32) -> i32 { if idx % 2 == 0 { sleep(ms(200)).await; } idx } fn ms(n: u64) -> Duration {...
tokio
rust
async_runtime
chunks_timeout.rs
#![warn(rust_2018_idioms)] #![cfg(all(feature = "time", feature = "sync", feature = "io-util"))] use tokio::time; use tokio_stream::{self as stream, StreamExt}; use tokio_test::assert_pending; use tokio_test::task; use futures::FutureExt; use std::time::Duration; #[tokio::test(start_paused = true)] async fn usage() ...
tokio
rust
async_runtime
mpsc_unbounded_stream.rs
use futures::{Stream, StreamExt}; use futures_core::FusedStream; use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; #[tokio::test] async fn size_hint_stream_open() { let (tx, rx) = mpsc::unbounded_channel(); tx.send(1).unwrap(); tx.send(2).unwrap(); let mut stream = Unbounded...
tokio
rust
async_runtime
stream_stream_map.rs
use futures::stream::iter; use tokio_stream::{self as stream, pending, Stream, StreamExt, StreamMap}; use tokio_test::{assert_ok, assert_pending, assert_ready, task}; use std::future::{poll_fn, Future}; use std::pin::{pin, Pin}; use std::task::Poll; mod support { pub(crate) mod mpsc; } use support::mpsc; macro_...
tokio
rust
async_runtime
stream_iter.rs
use std::iter; use tokio_stream::{self as stream, Stream}; use tokio_test::{assert_pending, assert_ready, task}; #[tokio::test] async fn coop() { let mut stream = task::spawn(stream::iter(iter::repeat(1))); for _ in 0..10_000 { if stream.poll_next().is_pending() { tokio::task::yield_now()....
tokio
rust
async_runtime
watch.rs
#![cfg(feature = "sync")] use tokio::sync::watch; use tokio_stream::wrappers::WatchStream; use tokio_stream::StreamExt; use tokio_test::assert_pending; use tokio_test::task::spawn; #[tokio::test] async fn watch_stream_message_not_twice() { let (tx, rx) = watch::channel("hello"); let mut counter = 0; let ...
tokio
rust
async_runtime
async_send_sync.rs
#![allow(clippy::diverging_sub_expression)] use std::rc::Rc; #[allow(dead_code)] type BoxStream<T> = std::pin::Pin<Box<dyn tokio_stream::Stream<Item = T>>>; #[allow(dead_code)] fn require_send<T: Send>(_t: &T) {} #[allow(dead_code)] fn require_sync<T: Sync>(_t: &T) {} #[allow(dead_code)] fn require_unpin<T: Unpin>(_...
tokio
rust
async_runtime
time_throttle.rs
#![warn(rust_2018_idioms)] #![cfg(all(feature = "time", feature = "sync", feature = "io-util"))] use futures_core::FusedStream; use tokio::time; use tokio_stream::{Stream, StreamExt}; use tokio_test::*; use std::time::Duration; #[test] fn throttle_can_be_created_outside_runtime() { let _stream = futures::stream:...
tokio
rust
async_runtime
stream_map_while.rs
use tokio_stream::StreamExt; #[tokio::test] async fn map_while_yields_until_closure_returns_none() { let mut stream = tokio_stream::iter(1..=10).map_while(|x| if x < 4 { Some(x + 3) } else { None }); assert_eq!(stream.next().await, Some(4)); assert_eq!(stream.next().await, Some(5)); assert_eq!(...
tokio
rust
async_runtime
mpsc_bounded_stream.rs
use futures::{task::noop_waker_ref, Stream, StreamExt}; use futures_core::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::sync::mpsc; use tokio_stream::wrappers::ReceiverStream; #[tokio::test] async fn size_hint_stream_open() { let (tx, rx) = mpsc::channel(4); tx.send(1).await.unwra...
tokio
rust
async_runtime
stream_collect.rs
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; use tokio_stream::{self as stream, StreamExt}; use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task}; mod support { pub(crate) mod mpsc; } use support::mpsc; #[allow(clippy::let_unit...
tokio
rust
async_runtime
mpsc.rs
use async_stream::stream; use tokio::sync::mpsc::{self, UnboundedSender}; use tokio_stream::Stream; pub fn unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>) { let (tx, mut rx) = mpsc::unbounded_channel(); let stream = stream! { while let Some(item) = rx.recv().await {...
tokio
rust
async_runtime
fuzz_stream_map.rs
#![no_main] use libfuzzer_sys::fuzz_target; use std::pin::Pin; use tokio_stream::{self as stream, Stream, StreamMap}; use tokio_test::{assert_pending, assert_ready, task}; macro_rules! assert_ready_none { ($($t:tt)*) => { match assert_ready!($($t)*) { None => {} Some(v) => panic!(...
tokio
rust
async_runtime
pending.rs
use crate::Stream; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; /// Stream for the [`pending`](fn@pending) function. #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct Pending<T>(PhantomData<T>); impl<T> Unpin for Pending<T> {} unsafe impl<T> Send for ...
tokio
rust
async_runtime
empty.rs
use crate::Stream; use futures_core::FusedStream; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; /// Stream for the [`empty`](fn@empty) function. #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct Empty<T>(PhantomData<T>); impl<T> Unpin for Empty<T> {} u...
tokio
rust
async_runtime
lib.rs
#![allow( clippy::cognitive_complexity, clippy::large_enum_variant, clippy::needless_doctest_main )] #![warn( missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub )] #![cfg_attr(docsrs, feature(doc_cfg))] #![doc(test( no_crate_inject, attr(deny(warnings, rus...
tokio
rust
async_runtime
iter.rs
use crate::Stream; use core::pin::Pin; use core::task::{Context, Poll}; /// Stream for the [`iter`](fn@iter) function. #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct Iter<I> { iter: I, #[cfg(not(feature = "rt"))] yield_amt: usize, } impl<I> Unpin for Iter<I> {} /// Converts...
tokio
rust
async_runtime
stream_close.rs
use crate::Stream; use futures_core::FusedStream; use pin_project_lite::pin_project; use std::pin::Pin; use std::task::{Context, Poll}; pin_project! { /// A `Stream` that wraps the values in an `Option`. /// /// Whenever the wrapped stream yields an item, this stream yields that item /// wrapped in `So...
tokio
rust
async_runtime
stream_ext.rs
use core::future::Future; use futures_core::Stream; mod all; use all::AllFuture; mod any; use any::AnyFuture; mod chain; pub use chain::Chain; pub(crate) mod collect; use collect::{Collect, FromStream}; mod filter; pub use filter::Filter; mod filter_map; pub use filter_map::FilterMap; mod fold; use fold::FoldFut...
tokio
rust
async_runtime
macros.rs
macro_rules! cfg_fs { ($($item:item)*) => { $( #[cfg(feature = "fs")] #[cfg_attr(docsrs, doc(cfg(feature = "fs")))] $item )* } } macro_rules! cfg_io_util { ($($item:item)*) => { $( #[cfg(feature = "io-util")] #[cfg_attr(doc...
tokio
rust
async_runtime
once.rs
use crate::Stream; use futures_core::FusedStream; use core::pin::Pin; use core::task::{Context, Poll}; /// Stream for the [`once`](fn@once) function. #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct Once<T> { value: Option<T>, } impl<I> Unpin for Once<I> {} /// Creates a stream that ...
tokio
rust
async_runtime
wrappers.rs
/// Error types for the wrappers. pub mod errors { cfg_sync! { pub use crate::wrappers::broadcast::BroadcastStreamRecvError; } } mod mpsc_bounded; pub use mpsc_bounded::ReceiverStream; mod mpsc_unbounded; pub use mpsc_unbounded::UnboundedReceiverStream; cfg_rt! { mod task; pub use task::JoinS...
tokio
rust
async_runtime
stream_map.rs
use crate::Stream; use std::borrow::Borrow; use std::future::poll_fn; use std::hash::Hash; use std::pin::Pin; use std::task::{ready, Context, Poll}; /// Combine many streams into one, indexing each source stream with a unique /// key. /// /// `StreamMap` is similar to [`StreamExt::merge`] in that it combines source /...
tokio
rust
async_runtime
mpsc_bounded.rs
use crate::Stream; use futures_core::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::sync::mpsc::Receiver; /// A wrapper around [`tokio::sync::mpsc::Receiver`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::sync::mpsc; /// use tokio_stream::wrappers::ReceiverStream;...
tokio
rust
async_runtime
signal_windows.rs
use crate::Stream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::signal::windows::{CtrlBreak, CtrlC}; /// A wrapper around [`CtrlC`] that implements [`Stream`]. /// /// [`CtrlC`]: struct@tokio::signal::windows::CtrlC /// [`Stream`]: trait@crate::Stream /// /// # Example /// /// ```no_run /// use tokio:...
tokio
rust
async_runtime
mpsc_unbounded.rs
use crate::Stream; use futures_core::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::sync::mpsc::UnboundedReceiver; /// A wrapper around [`tokio::sync::mpsc::UnboundedReceiver`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::sync::mpsc; /// use tokio_stream::wrapper...
tokio
rust
async_runtime
interval.rs
use crate::Stream; use futures_core::stream::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::time::{Instant, Interval}; /// A wrapper around [`Interval`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::time::{Duration, Instant, interval}; /// use tokio_stream::wrappe...
tokio
rust
async_runtime
tcp_listener.rs
use crate::Stream; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::net::{TcpListener, TcpStream}; /// A wrapper around [`TcpListener`] that implements [`Stream`]. /// /// # Example /// /// Accept connections from both IPv4 and IPv6 listeners in the same loop: /// /// ```no_run /// # #[cfg(no...
tokio
rust
async_runtime
task.rs
use crate::Stream; use futures_core::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::task::{JoinError, JoinSet}; /// A wrapper around [`tokio::task::JoinSet`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::task::JoinSet; /// use tokio_stream::wrappers::JoinSetStream...
tokio
rust
async_runtime
unix_listener.rs
use crate::Stream; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::net::{UnixListener, UnixStream}; /// A wrapper around [`UnixListener`] that implements [`Stream`]. /// /// # Example /// /// ```no_run /// use tokio::net::UnixListener; /// use tokio_stream::{StreamExt, wrappers::UnixListener...
tokio
rust
async_runtime
watch.rs
use std::pin::Pin; use tokio::sync::watch::Receiver; use futures_core::Stream; use tokio_util::sync::ReusableBoxFuture; use std::fmt; use std::task::{ready, Context, Poll}; use tokio::sync::watch::error::RecvError; /// A wrapper around [`tokio::sync::watch::Receiver`] that implements [`Stream`]. /// /// This stream ...
tokio
rust
async_runtime
signal_unix.rs
use crate::Stream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::signal::unix::Signal; /// A wrapper around [`Signal`] that implements [`Stream`]. /// /// # Example /// /// ```no_run /// use tokio::signal::unix::{signal, SignalKind}; /// use tokio_stream::{StreamExt, wrappers::SignalStream}; /// /// # ...
tokio
rust
async_runtime
broadcast.rs
use std::pin::Pin; use tokio::sync::broadcast::error::RecvError; use tokio::sync::broadcast::Receiver; use futures_core::Stream; use tokio_util::sync::ReusableBoxFuture; use std::fmt; use std::task::{ready, Context, Poll}; /// A wrapper around [`tokio::sync::broadcast::Receiver`] that implements [`Stream`]. /// /// ...
tokio
rust
async_runtime
read_dir.rs
use crate::Stream; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::fs::{DirEntry, ReadDir}; /// A wrapper around [`tokio::fs::ReadDir`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::fs::read_dir; /// use tokio_stream::{StreamExt, wrappers::ReadDirStream}; /// /// #...
tokio
rust
async_runtime
lines.rs
use crate::Stream; use pin_project_lite::pin_project; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::io::{AsyncBufRead, Lines}; pin_project! { /// A wrapper around [`tokio::io::Lines`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::io::Async...
tokio
rust
async_runtime
split.rs
use crate::Stream; use pin_project_lite::pin_project; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::io::{AsyncBufRead, Split}; pin_project! { /// A wrapper around [`tokio::io::Split`] that implements [`Stream`]. /// /// # Example /// /// ``` /// use tokio::io::Async...
tokio
rust
async_runtime
timeout.rs
use crate::stream_ext::{safe_delay, Fuse}; use crate::Stream; use tokio::time::{sleep, Instant, Sleep}; use core::future::Future; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; use std::fmt; use std::time::Duration; pin_project! { /// ...
tokio
rust
async_runtime
take_while.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`take_while`](super::StreamExt::take_while) method. #[must_use = "streams do nothing unless polled"] pub struct TakeWh...
tokio
rust
async_runtime
all.rs
use crate::Stream; use core::future::Future; use core::marker::PhantomPinned; use core::pin::Pin; use core::task::{ready, Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future for the [`all`](super::StreamExt::all) method. #[derive(Debug)] #[must_use = "futures do nothing unless you...
tokio
rust
async_runtime
chain.rs
use crate::stream_ext::Fuse; use crate::Stream; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream returned by the [`chain`](super::StreamExt::chain) method. pub struct Chain<T, U> { #[pin] a: ...
tokio
rust
async_runtime
skip_while.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`skip_while`](super::StreamExt::skip_while) method. #[must_use = "streams do nothing unless polled"] pub struct...
tokio
rust
async_runtime
timeout_repeating.rs
use crate::stream_ext::Fuse; use crate::{Elapsed, Stream}; use tokio::time::Interval; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream returned by the [`timeout_repeating`](super::StreamExt::timeout_repeating) m...
tokio
rust
async_runtime
peekable.rs
use std::pin::Pin; use std::task::{Context, Poll}; use futures_core::{FusedStream, Stream}; use pin_project_lite::pin_project; use crate::stream_ext::Fuse; use crate::StreamExt; pin_project! { /// Stream returned by the [`peekable`](super::StreamExt::peekable) method. pub struct Peekable<T: Stream> { ...
tokio
rust
async_runtime
skip.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`skip`](super::StreamExt::skip) method. #[must_use = "streams do nothing unless polled"] pub struct Skip<St> { ...
tokio
rust
async_runtime
merge.rs
use crate::stream_ext::Fuse; use crate::Stream; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream returned by the [`merge`](super::StreamExt::merge) method. pub struct Merge<T, U> { #[pin] a: Fuse<T>...
tokio
rust
async_runtime
collect.rs
use crate::Stream; use core::future::Future; use core::marker::{PhantomData, PhantomPinned}; use core::mem; use core::pin::Pin; use core::task::{ready, Context, Poll}; use pin_project_lite::pin_project; use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; use std::hash::Hash;...
tokio
rust
async_runtime
try_next.rs
use crate::stream_ext::Next; use crate::Stream; use core::future::Future; use core::marker::PhantomPinned; use core::pin::Pin; use core::task::{Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future for the [`try_next`](super::StreamExt::try_next) method. /// /// # Cancel safety ...
tokio
rust
async_runtime
throttle.rs
use crate::stream_ext::safe_delay; use crate::Stream; use futures_core::FusedStream; use tokio::time::{sleep, Duration, Instant, Sleep}; use std::future::Future; use std::pin::Pin; use std::task::{self, ready, Poll}; use pin_project_lite::pin_project; pub(super) fn throttle<T>(duration: Duration, stream: T) -> Throt...
tokio
rust
async_runtime
chunks_timeout.rs
use crate::stream_ext::Fuse; use crate::Stream; use tokio::time::{sleep, Sleep}; use core::future::Future; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; use std::time::Duration; pin_project! { /// Stream returned by the [`chunks_timeo...
tokio
rust
async_runtime
fuse.rs
use crate::Stream; use futures_core::FusedStream; use pin_project_lite::pin_project; use std::pin::Pin; use std::task::{ready, Context, Poll}; pin_project! { /// Stream returned by [`fuse()`][super::StreamExt::fuse]. #[derive(Debug)] pub struct Fuse<T> { #[pin] stream: Option<T>, } } ...
tokio
rust
async_runtime
next.rs
use crate::Stream; use core::future::Future; use core::marker::PhantomPinned; use core::pin::Pin; use core::task::{Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future for the [`next`](super::StreamExt::next) method. /// /// # Cancel safety /// /// This method is cancel saf...
tokio
rust
async_runtime
fold.rs
use crate::Stream; use core::future::Future; use core::marker::PhantomPinned; use core::pin::Pin; use core::task::{ready, Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future returned by the [`fold`](super::StreamExt::fold) method. #[derive(Debug)] #[must_use = "futures do nothing ...
tokio
rust
async_runtime
filter_map.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream returned by the [`filter_map`](super::StreamExt::filter_map) method. #[must_use = "streams do nothing unless polled"] pu...
tokio
rust
async_runtime
any.rs
use crate::Stream; use core::future::Future; use core::marker::PhantomPinned; use core::pin::Pin; use core::task::{ready, Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future for the [`any`](super::StreamExt::any) method. #[derive(Debug)] #[must_use = "futures do nothing unless you...
tokio
rust
async_runtime
take.rs
use crate::Stream; use core::cmp; use core::fmt; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`take`](super::StreamExt::take) method. #[must_use = "streams do nothing unless polled"] pub struct Tak...
tokio
rust
async_runtime
filter.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{ready, Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream returned by the [`filter`](super::StreamExt::filter) method. #[must_use = "streams do nothing unless polled"] pub struct...
tokio
rust
async_runtime
map_while.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`map_while`](super::StreamExt::map_while) method. #[must_use = "streams do nothing unless polled"] pub struct MapWhile...
tokio
rust
async_runtime
then.rs
use crate::Stream; use core::fmt; use core::future::Future; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`then`](super::StreamExt::then) method. #[must_use = "streams do nothing unless polled"] pub...
tokio
rust
async_runtime
map.rs
use crate::Stream; use core::fmt; use core::pin::Pin; use core::task::{Context, Poll}; use futures_core::FusedStream; use pin_project_lite::pin_project; pin_project! { /// Stream for the [`map`](super::StreamExt::map) method. #[must_use = "streams do nothing unless polled"] pub struct Map<St, F> { ...
tokio
rust
async_runtime
simple_echo_tcp.rs
use std::{thread::sleep, time::Duration}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpSocket}, runtime::Builder, sync::oneshot, }; const TCP_ENDPOINT: &str = "127.0.0.1:8080"; const NUM_MSGS: usize = 100; const MSG_SIZE: usize = 1024; fn main() { let rt = Builder::new_mu...
tokio
rust
async_runtime
poll_semaphore.rs
use std::future::Future; use std::sync::Arc; use std::task::Poll; use tokio::sync::{OwnedSemaphorePermit, Semaphore}; use tokio_util::sync::PollSemaphore; type SemRet = Option<OwnedSemaphorePermit>; fn semaphore_poll( sem: &mut PollSemaphore, ) -> tokio_test::task::Spawn<impl Future<Output = SemRet> + '_> { l...
tokio
rust
async_runtime
panic.rs
#![warn(rust_2018_idioms)] #![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery #![cfg(panic = "unwind")] use parking_lot::Mutex; use std::error::Error; use std::panic; use std::sync::Arc; use tokio::runtime::Runtime; use tokio::sync::mpsc::channel; use tokio::time::{Duration,...
tokio
rust
async_runtime
time_delay_queue.rs
#![allow(clippy::disallowed_names)] #![warn(rust_2018_idioms)] #![cfg(feature = "full")] use futures::StreamExt; use tokio::time::{self, sleep, sleep_until, Duration, Instant}; use tokio_test::{assert_pending, assert_ready, task}; use tokio_util::time::DelayQueue; macro_rules! poll { ($queue:ident) => { $...
tokio
rust
async_runtime
reusable_box.rs
use futures::future::FutureExt; use std::alloc::Layout; use std::future::Future; use std::marker::PhantomPinned; use std::pin::Pin; use std::rc::Rc; use std::task::{Context, Poll}; use tokio_util::sync::ReusableBoxFuture; #[test] // Clippy false positive; it's useful to be able to test the trait impls for any lifetime...
tokio
rust
async_runtime
tracing_task.rs
#![warn(rust_2018_idioms)] #![cfg(all(tokio_unstable, target_has_atomic = "64", feature = "rt"))] #![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads use tokio::task::JoinHandle; use tokio_util::task::LocalPoolHandle; use tracing_mock::{expect, subscriber}; /// Tasks spawned with `spawn_pinned` and `spaw...
tokio
rust
async_runtime
codecs.rs
#![warn(rust_2018_idioms)] use tokio_util::codec::{AnyDelimiterCodec, BytesCodec, Decoder, Encoder, LinesCodec}; use bytes::{BufMut, Bytes, BytesMut}; #[test] fn bytes_decoder() { let mut codec = BytesCodec::new(); let buf = &mut BytesMut::new(); buf.put_slice(b"abc"); assert_eq!("abc", codec.decode(...
tokio
rust
async_runtime
task_join_map.rs
#![warn(rust_2018_idioms)] #![cfg(feature = "join-map")] use std::panic::AssertUnwindSafe; use futures::future::{pending, FutureExt}; use tokio::sync::oneshot; use tokio::task::LocalSet; use tokio::time::Duration; use tokio_util::task::JoinMap; fn rt() -> tokio::runtime::Runtime { tokio::runtime::Builder::new_cu...
tokio
rust
async_runtime
compat.rs
#![cfg(feature = "compat")] #![cfg(not(target_os = "wasi"))] // WASI does not support all fs operations #![warn(rust_2018_idioms)] use futures_io::SeekFrom; use futures_util::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; use std::io::{self, IoSlice}; use std::pin::Pin; use std::task::{Context, Poll}; use tempfile::Name...
tokio
rust
async_runtime
framed_stream.rs
use futures_core::stream::Stream; use std::{io, pin::Pin}; use tokio_test::{assert_ready, io::Builder, task}; use tokio_util::codec::{BytesCodec, FramedRead}; macro_rules! pin { ($id:ident) => { Pin::new(&mut $id) }; } macro_rules! assert_read { ($e:expr, $n:expr) => {{ let val = assert_re...
tokio
rust
async_runtime
length_delimited.rs
#![warn(rust_2018_idioms)] use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio_test::task; use tokio_test::{ assert_err, assert_ok, assert_pending, assert_ready, assert_ready_err, assert_ready_ok, }; use tokio_util::codec::*; use bytes::{BufMut, Bytes, BytesMut}; use futures::{pin_mut, Sink, Stream}; use s...
tokio
rust
async_runtime
framed_write.rs
#![warn(rust_2018_idioms)] use tokio::io::AsyncWrite; use tokio_test::{assert_ready, task}; use tokio_util::codec::{Encoder, FramedWrite}; use bytes::{BufMut, BytesMut}; use futures_sink::Sink; use std::collections::VecDeque; use std::io::{self, Write}; use std::pin::Pin; use std::task::Poll::{Pending, Ready}; use st...
tokio
rust
async_runtime
io_stream_reader.rs
#![warn(rust_2018_idioms)] use bytes::Bytes; use tokio::io::AsyncReadExt; use tokio_stream::iter; use tokio_util::io::StreamReader; #[tokio::test] async fn test_stream_reader() -> std::io::Result<()> { let stream = iter(vec![ std::io::Result::Ok(Bytes::from_static(&[])), Ok(Bytes::from_static(&[0,...
tokio
rust
async_runtime
mpsc.rs
use futures::sink::SinkExt; use std::future::poll_fn; use tokio::sync::mpsc::channel; use tokio_test::task::spawn; use tokio_test::{ assert_ok, assert_pending, assert_ready, assert_ready_eq, assert_ready_err, assert_ready_ok, }; use tokio_util::sync::PollSender; #[tokio::test] async fn simple() { let (send, mu...
tokio
rust
async_runtime
framed_read.rs
#![warn(rust_2018_idioms)] use tokio::io::{AsyncRead, ReadBuf}; use tokio_test::assert_ready; use tokio_test::task; use tokio_util::codec::{Decoder, FramedRead}; use bytes::{Buf, BytesMut}; use futures::Stream; use std::collections::VecDeque; use std::io; use std::pin::Pin; use std::task::Poll::{Pending, Ready}; use ...
tokio
rust
async_runtime
task_join_queue.rs
#![warn(rust_2018_idioms)] use std::task::Context; use futures_test::task::new_count_waker; use tokio::sync::oneshot; use tokio::task::yield_now; use tokio::time::Duration; use tokio_test::{assert_pending, assert_ready, task}; use tokio_util::task::JoinQueue; #[tokio::test] async fn test_join_queue_no_spurious_wakeu...
tokio
rust
async_runtime
task_tracker.rs
#![warn(rust_2018_idioms)] use futures::future::pending; use std::rc::Rc; use tokio::sync::mpsc; use tokio::task::LocalSet; use tokio_test::{assert_pending, assert_ready, task}; use tokio_util::task::TaskTracker; #[test] fn open_close() { let tracker = TaskTracker::new(); assert!(!tracker.is_closed()); as...
tokio
rust
async_runtime
io_reader_stream.rs
#![warn(rust_2018_idioms)] use futures_core::FusedStream; use std::pin::Pin; use std::task::{Context, Poll}; use tokio::io::{AsyncRead, ReadBuf}; use tokio_stream::StreamExt; /// produces at most `remaining` zeros, that returns error. /// each time it reads at most 31 byte. struct Reader { remaining: usize, } im...
tokio
rust
async_runtime
io_sink_writer.rs
#![warn(rust_2018_idioms)] use bytes::Bytes; use futures_util::SinkExt; use std::io::{self, Error, ErrorKind}; use tokio::io::AsyncWriteExt; use tokio_util::codec::{Encoder, FramedWrite}; use tokio_util::io::{CopyToBytes, SinkWriter}; use tokio_util::sync::PollSender; #[test] fn test_pinned_sink_accessors() { use...
tokio
rust
async_runtime
framed.rs
#![warn(rust_2018_idioms)] use tokio_stream::StreamExt; use tokio_test::assert_ok; use tokio_util::codec::{Decoder, Encoder, Framed, FramedParts}; use bytes::{Buf, BufMut, BytesMut}; use std::io::{self, Read}; use std::pin::Pin; use std::task::{Context, Poll}; const INITIAL_CAPACITY: usize = 8 * 1024; /// Encode an...
tokio
rust
async_runtime
io_write_all_vectored.rs
#![warn(rust_2018_idioms)] #![cfg(feature = "full")] use tokio::io::AsyncWrite; use tokio_util::io::write_all_vectored; use bytes::BytesMut; use std::io::IoSlice; use std::io::{self, ErrorKind}; use std::pin::Pin; use std::task::{Context, Poll}; struct PartialVectoredWriter { buf: BytesMut, max_write: usize,...
tokio
rust
async_runtime
spawn_pinned.rs
#![warn(rust_2018_idioms)] #![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads use std::rc::Rc; use std::sync::Arc; use tokio::sync::Barrier; use tokio_util::task; /// Simple test of running a !Send future via spawn_pinned #[tokio::test] async fn can_spawn_not_send_future() { let pool = task::LocalPo...
tokio
rust
async_runtime
future.rs
use std::{ future::{pending, ready, Future}, task::{Context, Poll}, }; use futures_test::task::new_count_waker; use tokio::pin; use tokio_test::{assert_pending, assert_ready_eq}; use tokio_util::{future::FutureExt, sync::CancellationToken}; #[derive(Default)] struct ReadyOnTheSecondPollFuture { polled: bo...
tokio
rust
async_runtime
io_simplex.rs
use futures::pin_mut; use futures_test::task::noop_context; use std::io::IoSlice; use std::task::Poll; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}; use tokio_test::task::spawn; use tokio_test::{assert_pending, assert_ready}; use tokio_util::io::simplex; /// Sanity check for single-thre...
tokio
rust
async_runtime
abort_on_drop.rs
use tokio::{sync::oneshot, task::yield_now}; use tokio_util::task::{AbortOnDrop, AbortOnDropHandle}; #[tokio::test] async fn aborts_task_on_drop() { let (mut tx, rx) = oneshot::channel::<bool>(); let handle = tokio::spawn(async move { let _ = rx.await; }); let handle = AbortOnDropHandle::new(ha...
tokio
rust
async_runtime
io_read_arc.rs
#![warn(rust_2018_idioms)] #![cfg(feature = "full")] use std::io::ErrorKind; use tokio_util::io::read_exact_arc; #[tokio::test] async fn retry_on_io_interrupted() { let reader = tokio_test::io::Builder::new() .read_error(ErrorKind::Interrupted.into()) .read(b"ab") .read_error(ErrorKind::In...
tokio
rust
async_runtime
io_sync_bridge.rs
#![cfg(feature = "io-util")] #![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads use std::error::Error; use std::io::{Cursor, Read, Result as IoResult, Write}; use tokio::io::{AsyncRead, AsyncReadExt}; use tokio_util::io::SyncIoBridge; async fn test_reader_len( r: impl AsyncRead + Unpin + Send + 'sta...
tokio
rust
async_runtime
sync_cancellation_token.rs
#![warn(rust_2018_idioms)] use tokio::pin; use tokio::sync::oneshot; use tokio_util::sync::{CancellationToken, WaitForCancellationFuture}; use core::future::Future; use core::hash::Hash; use core::task::{Context, Poll}; use futures_test::task::new_count_waker; use std::hash::{DefaultHasher, Hasher}; #[test] fn cance...
tokio
rust
async_runtime
context.rs
#![cfg(feature = "rt")] #![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #![warn(rust_2018_idioms)] use tokio::runtime::Builder; use tokio::time::*; use tokio_util::context::RuntimeExt; #[test] fn tokio_context_with_another_runtime() { let rt1 = Builder::new_multi_thread() .worker_threads(...
tokio
rust
async_runtime
udp.rs
#![warn(rust_2018_idioms)] #![cfg(not(target_os = "wasi"))] // Wasi doesn't support UDP #![cfg(not(miri))] // No UDP sockets in Miri. #![cfg(not(loom))] // No udp / UdpFramed in loom use tokio::net::UdpSocket; use tokio_stream::StreamExt; use tokio_util::codec::{Decoder, Encoder, LinesCodec}; use tokio_util::udp::UdpF...
tokio
rust
async_runtime
compat.rs
use pin_project_lite::pin_project; use std::io; use std::pin::Pin; use std::task::{ready, Context, Poll}; pin_project! { /// A compatibility layer that allows conversion between the /// `tokio::io` and `futures-io` `AsyncRead` and `AsyncWrite` traits. #[derive(Copy, Clone, Debug)] pub struct Compat<T> ...
tokio
rust
async_runtime
lib.rs
#![allow(clippy::needless_doctest_main)] #![warn( missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub )] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) ))] #![cfg_attr(docsrs, feature(doc_cfg))] #[macro_use] m...