pub struct Intermediary<Downstream, Upstream, Policy = NoPipeline> { /* private fields */ }Expand description
Owns two independently typed sides and optional pipeline orchestration.
Downstream is normally a server-role session facing a client and Upstream
is normally a client-role session facing PostgreSQL. No phase, transport,
authentication mechanism, or cleanliness index is coupled between them.
Policy defaults to NoPipeline; call Self::with_pipeline to opt into
bounded pipelining without changing either session type.
Implementations§
Source§impl<Downstream, Upstream> Intermediary<Downstream, Upstream, NoPipeline>
impl<Downstream, Upstream> Intermediary<Downstream, Upstream, NoPipeline>
Source§impl<Downstream, Upstream, Policy: PipelinePolicy> Intermediary<Downstream, Upstream, Policy>
impl<Downstream, Upstream, Policy: PipelinePolicy> Intermediary<Downstream, Upstream, Policy>
Sourcepub fn with_pipeline<Next: PipelinePolicy>(
self,
policy: Next,
) -> Intermediary<Downstream, Upstream, Next>
pub fn with_pipeline<Next: PipelinePolicy>( self, policy: Next, ) -> Intermediary<Downstream, Upstream, Next>
Replaces the pipeline policy while no pipeline operations are outstanding.
§Panics
Panics if operations were accepted before replacing the policy.
Sourcepub const fn pipeline(&self) -> &Pipeline<Policy>
pub const fn pipeline(&self) -> &Pipeline<Policy>
Returns the reusable request/response pipeline component.
Sourcepub const fn pipeline_mut(&mut self) -> &mut Pipeline<Policy>
pub const fn pipeline_mut(&mut self) -> &mut Pipeline<Policy>
Returns mutable access to bounded pipeline orchestration.
Sourcepub const fn downstream(&self) -> &Downstream
pub const fn downstream(&self) -> &Downstream
Borrows the client-facing side without weakening its typestate.
Sourcepub const fn upstream(&self) -> &Upstream
pub const fn upstream(&self) -> &Upstream
Borrows the upstream-facing side without weakening its typestate.
Sourcepub const fn sides_mut(&mut self) -> (&mut Downstream, &mut Upstream)
pub const fn sides_mut(&mut self) -> (&mut Downstream, &mut Upstream)
Mutably borrows both sides for transport-level orchestration.
Sourcepub fn into_parts(self) -> (Downstream, Upstream)
pub fn into_parts(self) -> (Downstream, Upstream)
Deliberately separates the independently typed sessions.
Sourcepub fn transition_downstream<Next, Output, Error>(
self,
transition: impl FnOnce(Downstream) -> Result<(Next, Output), (Downstream, Error)>,
) -> IntermediaryTransition<Self, Intermediary<Next, Upstream, Policy>, Output, Error>
pub fn transition_downstream<Next, Output, Error>( self, transition: impl FnOnce(Downstream) -> Result<(Next, Output), (Downstream, Error)>, ) -> IntermediaryTransition<Self, Intermediary<Next, Upstream, Policy>, Output, Error>
Applies one fallible downstream transition while retaining the upstream session unchanged.
A rejected transition must return its original downstream value, allowing this method to reconstruct the original intermediary without runtime state.
§Errors
Returns the reconstructed intermediary and transition error when the downstream side rejects the transition.
Sourcepub fn transition_upstream<Next, Output, Error>(
self,
transition: impl FnOnce(Upstream) -> Result<(Next, Output), (Upstream, Error)>,
) -> IntermediaryTransition<Self, Intermediary<Downstream, Next, Policy>, Output, Error>
pub fn transition_upstream<Next, Output, Error>( self, transition: impl FnOnce(Upstream) -> Result<(Next, Output), (Upstream, Error)>, ) -> IntermediaryTransition<Self, Intermediary<Downstream, Next, Policy>, Output, Error>
Applies one fallible upstream transition while retaining the downstream session unchanged.
§Errors
Returns the reconstructed intermediary and transition error when the upstream side rejects the transition.
Sourcepub fn inspect<Message, Output, Error>(
&mut self,
message: Message,
inspect: impl FnOnce(&mut Downstream, &mut Upstream, Message) -> Result<Output, Error>,
) -> Result<Output, Error>
pub fn inspect<Message, Output, Error>( &mut self, message: Message, inspect: impl FnOnce(&mut Downstream, &mut Upstream, Message) -> Result<Output, Error>, ) -> Result<Output, Error>
Runs custom synchronous policy with mutable access to both sides.
The message and result types are chosen by downstream code; pg-proto
neither prescribes a rewrite policy nor advances either session implicitly.
§Errors
Returns any error produced by the inspection policy.
Sourcepub async fn inspect_async<Message, Output, Error, Work>(
&mut self,
message: Message,
inspect: impl FnOnce(&mut Downstream, &mut Upstream, Message) -> Work,
) -> Result<Output, Error>
pub async fn inspect_async<Message, Output, Error, Work>( &mut self, message: Message, inspect: impl FnOnce(&mut Downstream, &mut Upstream, Message) -> Work, ) -> Result<Output, Error>
Runs custom asynchronous policy with mutable access to both sides.
§Errors
Returns any error produced by the asynchronous inspection policy.