use std::future::Future;
use saddle_admission::{
DbPermitDomain, DbRequestPermit, DbRouteResources, ManagedBytes, ManagedResponse,
ManagedResponseOutput, RequestMemory,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ResponseOutcomeClass {
Success,
InvalidRequest,
BusinessRejected,
Unavailable,
Internal,
}
pub struct CompiledResponseOutcome {
class: ResponseOutcomeClass,
payload: ManagedResponse,
}
impl CompiledResponseOutcome {
pub fn success(payload: ManagedResponse) -> Self {
Self {
class: ResponseOutcomeClass::Success,
payload,
}
}
pub fn invalid_request(payload: ManagedResponse) -> Self {
Self {
class: ResponseOutcomeClass::InvalidRequest,
payload,
}
}
pub fn business_rejected(payload: ManagedResponse) -> Self {
Self {
class: ResponseOutcomeClass::BusinessRejected,
payload,
}
}
pub fn unavailable(payload: ManagedResponse) -> Self {
Self {
class: ResponseOutcomeClass::Unavailable,
payload,
}
}
pub fn internal(payload: ManagedResponse) -> Self {
Self {
class: ResponseOutcomeClass::Internal,
payload,
}
}
pub(crate) fn class(&self) -> ResponseOutcomeClass {
self.class
}
pub(crate) fn payload(&self) -> &ManagedResponse {
&self.payload
}
}
impl ManagedResponseOutput for CompiledResponseOutcome {
fn managed_response(&self) -> &ManagedResponse {
&self.payload
}
}
pub use crate::admission::{
CompiledRetryToken, OfficialCompiledDriverFinalizer, OfficialCompiledLiveSnapshot,
OfficialCompiledRouteCoordinator, OfficialCompiledRuntimeFinalizer,
OfficialCompiledShutdownReport, OfficialCompiledTcpOutcome, OfficialHttpRouteCoordinator,
OfficialHttpTcpOutcome, OfficialTcpAttemptProfile, OfficialTcpRejectReason,
OfficialTcpStopReason, PublishedTcpIdentity, WaitingCompiledTcp, WaitingHttpTcp,
};
pub trait CompiledRouteAdapter: Send + Sync + 'static {
type Proof: Copy + Send + Sync + Unpin + 'static;
type Context: Send + Unpin + 'static;
type Error: Send + 'static;
type Future: Future<Output = Result<ManagedResponse, Self::Error>> + Send + 'static;
fn managed_commitment(&self, proof: Self::Proof) -> Result<usize, Self::Error>;
fn response_capacity(&self, proof: Self::Proof) -> Result<usize, Self::Error>;
fn db_resources<'a>(
&self,
proof: Self::Proof,
domain: Option<&'a DbPermitDomain>,
) -> Result<DbRouteResources<'a>, Self::Error>;
fn execute(
&self,
proof: Self::Proof,
context: Self::Context,
body: ManagedBytes,
permit: Option<DbRequestPermit>,
memory: &RequestMemory,
) -> Result<Self::Future, Self::Error>;
}
pub trait ClassifiedCompiledRouteAdapter: Send + Sync + 'static {
type Proof: Copy + Send + Sync + Unpin + 'static;
type Context: Send + Unpin + 'static;
type Error: Send + 'static;
type Future: Future<Output = CompiledResponseOutcome> + Send + 'static;
fn managed_commitment(&self, proof: Self::Proof) -> Result<usize, Self::Error>;
fn response_capacity(&self, proof: Self::Proof) -> Result<usize, Self::Error>;
fn db_resources<'a>(
&self,
proof: Self::Proof,
domain: Option<&'a DbPermitDomain>,
) -> Result<DbRouteResources<'a>, Self::Error>;
fn execute(
&self,
proof: Self::Proof,
context: Self::Context,
body: ManagedBytes,
permit: Option<DbRequestPermit>,
memory: &RequestMemory,
) -> Self::Future;
}