futures: make select_(slice|array) hang intead of panicking if empty.

This commit is contained in:
Dario Nieuwenhuis 2022-08-28 21:28:26 +02:00
parent 3763baf8fa
commit 973f3b513f

View File

@ -199,11 +199,8 @@ pub struct SelectArray<Fut, const N: usize> {
/// completion the item resolved will be returned, along with the index of the /// completion the item resolved will be returned, along with the index of the
/// future that was ready. /// future that was ready.
/// ///
/// # Panics /// If the array is empty, the resulting future will be Pending forever.
///
/// This function will panic if the array specified contains no items.
pub fn select_array<Fut: Future, const N: usize>(arr: [Fut; N]) -> SelectArray<Fut, N> { pub fn select_array<Fut: Future, const N: usize>(arr: [Fut; N]) -> SelectArray<Fut, N> {
assert!(N > 0);
SelectArray { inner: arr } SelectArray { inner: arr }
} }
@ -247,11 +244,8 @@ pub struct SelectSlice<'a, Fut> {
/// completion the item resolved will be returned, along with the index of the /// completion the item resolved will be returned, along with the index of the
/// future that was ready. /// future that was ready.
/// ///
/// # Panics /// If the slice is empty, the resulting future will be Pending forever.
///
/// This function will panic if the slice specified contains no items.
pub fn select_slice<'a, Fut: Future>(slice: &'a mut [Fut]) -> SelectSlice<'a, Fut> { pub fn select_slice<'a, Fut: Future>(slice: &'a mut [Fut]) -> SelectSlice<'a, Fut> {
assert!(!slice.is_empty());
SelectSlice { inner: slice } SelectSlice { inner: slice }
} }