1 | use super::assert_stream; |
2 | use crate::stream::{AbortHandle, Abortable}; |
3 | use crate::Stream; |
4 | |
5 | /// Creates a new `Abortable` stream and an `AbortHandle` which can be used to stop it. |
6 | /// |
7 | /// This function is a convenient (but less flexible) alternative to calling |
8 | /// `AbortHandle::new` and `Abortable::new` manually. |
9 | /// |
10 | /// This function is only available when the `std` or `alloc` feature of this |
11 | /// library is activated, and it is activated by default. |
12 | pub fn abortable<St>(stream: St) -> (Abortable<St>, AbortHandle) |
13 | where |
14 | St: Stream, |
15 | { |
16 | let (handle, reg) = AbortHandle::new_pair(); |
17 | let abortable = assert_stream::<St::Item, _>(Abortable::new(stream, reg)); |
18 | (abortable, handle) |
19 | } |
20 | |