Skip to main content

SinkStack

Struct SinkStack 

Source
pub struct SinkStack<L = ()> { /* private fields */ }
Expand description

Builds a sink stack in record-entry order.

The first tier call becomes the outermost tier and receives records first. Each later tier receives records only when the tier before it forwards them; terminal finishes the stack with its final sink.

The builder introduces no boxing, dynamic dispatch, runtime collection, or store calls. Finishing it produces the existing nested Tier types.

use std::convert::Infallible;
use std::time::Duration;

use meathook::{
    FlushPolicy, JsonlStore, MemStore, Sink, SinkStack, WindowMeta,
};

struct Terminal;

impl Sink<i32> for Terminal {
    type Error = Infallible;

    async fn ingest(
        &mut self,
        _: &WindowMeta,
        _: Vec<i32>,
    ) -> Result<(), Self::Error> {
        Ok(())
    }

    async fn flush(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

let sink = SinkStack::new()
    .tier(
        MemStore::new(),
        FlushPolicy::new(Duration::from_secs(300), 10_000),
    )
    .tier(JsonlStore::new("spool"), FlushPolicy::hourly())
    .terminal(Terminal);

// Concrete type, inferred without boxing or `dyn Sink`.
let _: meathook::Tier<
    i32,
    MemStore<i32>,
    meathook::Tier<i32, JsonlStore<i32>, Terminal>,
> = sink;

Implementations§

Source§

impl SinkStack<()>

Source

pub const fn new() -> Self

Start an empty sink stack.

Source§

impl<L> SinkStack<L>

Source

pub fn tier<St>( self, store: St, policy: FlushPolicy, ) -> SinkStack<(St, FlushPolicy, L)>

Add the next tier in record-entry order.

Source

pub fn terminal<R, S>(self, sink: S) -> <L as BuildSinkStack<R, S>>::Output
where S: Sink<R>, L: BuildSinkStack<R, S>,

Finish the stack with its terminal sink.

The record type is normally inferred from the stores, terminal, or surrounding pipeline. For a terminal that implements Sink for multiple record types, specify it explicitly with terminal::<MyRecord, _>(sink).

Trait Implementations§

Source§

impl Default for SinkStack<()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<L> Freeze for SinkStack<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for SinkStack<L>
where L: RefUnwindSafe,

§

impl<L> Send for SinkStack<L>
where L: Send,

§

impl<L> Sync for SinkStack<L>
where L: Sync,

§

impl<L> Unpin for SinkStack<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for SinkStack<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for SinkStack<L>
where L: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more