grafbase_sdk/host_io/pubsub.rs
1//! Subscriber module providing interfaces for consuming field outputs from streams.
2//!
3//! This module defines the core `Subscriber` trait that abstracts over different
4//! implementations of subscribing to field output streams, allowing extensions to
5//! handle field outputs in a transport-agnostic way.
6
7use crate::{types::FieldOutput, Error};
8
9pub mod nats;
10
11/// A trait for consuming field outputs from streams.
12///
13/// This trait provides an abstraction over different implementations
14/// of subscriptions to field output streams. Implementors should handle
15/// the details of their specific transport mechanism while providing a
16/// consistent interface for consumers.
17pub trait Subscription {
18 /// Retrieves the next field output from the subscription.
19 ///
20 /// Returns:
21 /// - `Ok(Some(FieldOutput))` if a field output was available
22 /// - `Ok(None)` if the subscription has ended normally
23 /// - `Err(Error)` if an error occurred while retrieving the next field output
24 fn next(&mut self) -> Result<Option<FieldOutput>, Error>;
25}