ppoppo-infra 0.1.0

Backend-agnostic infrastructure traits for caching, queuing, and messaging
Documentation
//! Composite pub/sub trait binding Publisher and Subscriber to the same backend.

use async_trait::async_trait;

use crate::Result;
use crate::publisher::Publisher;
use crate::subscriber::Subscriber;

/// Composite pub/sub: publish + subscriber creation.
///
/// Publisher와 Subscriber는 반드시 같은 백엔드의 같은 채널을 공유한다.
/// 이 제약을 타입 시스템으로 표현하기 위해 composite trait으로 결합.
///
/// `PubSub: Publisher` 상속이므로, `Arc<dyn PubSub>`는 `Arc<dyn Publisher>`로
/// upcast 가능 (Rust 1.76+ trait upcasting).
#[async_trait]
pub trait PubSub: Publisher {
    /// Create a subscriber connected to the given channels.
    ///
    /// The returned subscriber holds a dedicated connection.
    /// Callers should keep the subscriber alive for the duration of the subscription.
    async fn subscribe(&self, channels: &[&str]) -> Result<Box<dyn Subscriber>>;
}