1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-08-07 15:20:55 +00:00
continuwuity/src/core/utils/stream/ignore.rs
Jason Volk 6f1d50dda3 panic on otherwise ignored errors in debug mode
Signed-off-by: Jason Volk <jason@zemos.net>
2024-11-25 02:54:29 +00:00

30 lines
799 B
Rust

use futures::{future::ready, Stream, StreamExt, TryStream};
use crate::{Error, Result};
pub trait TryIgnore<'a, Item> {
fn ignore_err(self) -> impl Stream<Item = Item> + Send + 'a;
fn ignore_ok(self) -> impl Stream<Item = Error> + Send + 'a;
}
impl<'a, T, Item> TryIgnore<'a, Item> for T
where
T: Stream<Item = Result<Item>> + TryStream + Send + 'a,
Item: Send + 'a,
{
#[cfg(debug_assertions)]
#[inline]
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a {
use super::TryExpect;
self.expect_ok()
}
#[cfg(not(debug_assertions))]
#[inline]
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a { self.filter_map(|res| ready(res.ok())) }
#[inline]
fn ignore_ok(self: T) -> impl Stream<Item = Error> + Send + 'a { self.filter_map(|res| ready(res.err())) }
}