Skip to main content

rivet_core/
dispatch.rs

1use std::any::Any;
2use std::sync::Arc;
3
4use rivet_foundation::ConfigValue;
5use rivet_http::{Request, Response};
6
7use crate::error::RivetError;
8
9/// Runtime dispatch boundary used by adapters.
10///
11/// Adapters translate transport-specific requests to [`Request`], call this
12/// method, then translate the resulting [`Response`] back to their transport.
13pub trait Dispatcher: Send + Sync {
14    /// Dispatch one request through routing and middleware.
15    fn dispatch(&self, req: Request) -> Response;
16
17    /// Read a config value when available (default: unsupported).
18    fn config_value(&self, _key: &str) -> Option<ConfigValue> {
19        None
20    }
21
22    /// Resolve a typed service by type name from the underlying app container.
23    fn resolve_any(
24        &self,
25        _type_name: &'static str,
26    ) -> Result<Arc<dyn Any + Send + Sync>, RivetError> {
27        Err(RivetError::Dispatch(
28            "app container access is not available on this dispatcher".to_string(),
29        ))
30    }
31}