File tree Expand file tree Collapse file tree 4 files changed +27
-1
lines changed
futures-util/src/stream/stream Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 4646 St : Stream ,
4747 St :: Item : Future ,
4848 {
49+ assert ! ( n > 0 ) ;
4950 Self {
5051 stream : super :: Fuse :: new ( stream) ,
5152 in_progress_queue : FuturesUnordered :: new ( ) ,
Original file line number Diff line number Diff line change 4444 St :: Item : Future ,
4545{
4646 pub ( super ) fn new ( stream : St , n : usize ) -> Self {
47+ assert ! ( n > 0 ) ;
4748 Self {
4849 stream : super :: Fuse :: new ( stream) ,
4950 in_progress_queue : FuturesOrdered :: new ( ) ,
Original file line number Diff line number Diff line change @@ -1142,6 +1142,10 @@ pub trait StreamExt: Stream {
11421142 ///
11431143 /// This method is only available when the `std` or `alloc` feature of this
11441144 /// library is activated, and it is activated by default.
1145+ ///
1146+ /// # Panics
1147+ ///
1148+ /// This method will panic if `n` is zero.
11451149 #[ cfg_attr( feature = "cfg-target-has-atomic" , cfg( target_has_atomic = "ptr" ) ) ]
11461150 #[ cfg( feature = "alloc" ) ]
11471151 fn buffered ( self , n : usize ) -> Buffered < Self >
@@ -1165,6 +1169,10 @@ pub trait StreamExt: Stream {
11651169 /// This method is only available when the `std` or `alloc` feature of this
11661170 /// library is activated, and it is activated by default.
11671171 ///
1172+ /// # Panics
1173+ ///
1174+ /// This method will panic if `n` is zero.
1175+ ///
11681176 /// # Examples
11691177 ///
11701178 /// ```
Original file line number Diff line number Diff line change 1- use futures:: channel:: mpsc;
1+ use futures:: { channel:: mpsc, future :: BoxFuture } ;
22use futures:: executor:: block_on;
33use futures:: future:: { self , Future } ;
44use futures:: sink:: SinkExt ;
@@ -118,6 +118,22 @@ fn take_until() {
118118 } ) ;
119119}
120120
121+ #[ test]
122+ #[ should_panic]
123+ fn buffered_panic_on_cap_zero ( ) {
124+ let ( _, rx1) = mpsc:: channel :: < BoxFuture < ( ) > > ( 1 ) ;
125+
126+ let _ = rx1. buffered ( 0 ) ;
127+ }
128+
129+ #[ test]
130+ #[ should_panic]
131+ fn buffer_unordered_panic_on_cap_zero ( ) {
132+ let ( _, rx1) = mpsc:: channel :: < BoxFuture < ( ) > > ( 1 ) ;
133+
134+ let _ = rx1. buffer_unordered ( 0 ) ;
135+ }
136+
121137#[ test]
122138#[ should_panic]
123139fn chunks_panic_on_cap_zero ( ) {
You can’t perform that action at this time.
0 commit comments