open_feature_flagd/resolver/in_process/storage/connector/
mod.rs

1pub mod file;
2pub mod grpc;
3
4use std::collections::HashMap;
5use std::sync::Arc;
6use tokio::sync::Mutex;
7use tokio::sync::mpsc::Receiver;
8
9/// Payload sent through the connector stream containing flag data or errors
10#[derive(Debug, Clone)]
11pub struct QueuePayload {
12    /// Type of payload (Data or Error)
13    pub payload_type: QueuePayloadType,
14    /// Flag configuration data (JSON string) or error message
15    pub flag_data: String,
16    /// Optional metadata associated with the sync
17    pub metadata: Option<HashMap<String, serde_json::Value>>,
18}
19
20/// Type of payload in the queue
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum QueuePayloadType {
23    /// Successful data payload
24    Data,
25    /// Error payload
26    Error,
27}
28
29use crate::error::FlagdError;
30
31/// Trait for flag configuration connectors (gRPC, file, etc.)
32///
33/// Connectors are responsible for fetching flag configurations from external sources
34/// and providing them as a stream of payloads. Implementations must be thread-safe
35/// (Send + Sync) as they may be used in async contexts.
36#[async_trait::async_trait]
37pub trait Connector: Send + Sync {
38    /// Initialize the connector and start fetching data
39    async fn init(&self) -> Result<(), FlagdError>;
40
41    /// Gracefully shutdown the connector and release resources
42    async fn shutdown(&self) -> Result<(), FlagdError>;
43
44    /// Get the stream of payloads from this connector
45    fn get_stream(&self) -> Arc<Mutex<Option<Receiver<QueuePayload>>>>;
46}