vector/sources/kubernetes_logs/transform_utils/
optional.rs

1//! Optional transform.
2
3#![deny(missing_docs)]
4
5use std::pin::Pin;
6
7use futures::Stream;
8
9use crate::event::EventContainer;
10use crate::transforms::TaskTransform;
11
12/// Optional transform.
13/// Passes events through the specified transform is any, otherwise passes them,
14/// as-is.
15/// Useful to avoid boxing the transforms.
16#[derive(Clone, Debug)]
17pub struct Optional<T>(pub Option<T>);
18
19impl<T: TaskTransform<E>, E: EventContainer + 'static> TaskTransform<E> for Optional<T> {
20    fn transform(
21        self: Box<Self>,
22        task: Pin<Box<dyn Stream<Item = E> + Send>>,
23    ) -> Pin<Box<dyn Stream<Item = E> + Send>>
24    where
25        Self: 'static,
26    {
27        match self.0 {
28            Some(val) => Box::new(val).transform(task),
29            None => task,
30        }
31    }
32}