pub struct SegmentProcessor { /* private fields */ }Expand description
Runs an OutcomeSegment as a Tower Service<Exchange>.
Bridges segment-mode pipelines (which produce PipelineOutcome) into the
Tower-result world so they can be wrapped by ProcessorLayer
implementations. Completed and Failed map straight through;
Stopped(ex) maps to Ok(ex) after UNCONDITIONALLY setting the
CamelStop property to true, so run_steps re-derives the stop at the
next Process step. The unconditional overwrite is deliberate: an exchange
carrying CamelStop = false from an earlier step must not defeat the
re-derivation.
Implementations§
Source§impl SegmentProcessor
impl SegmentProcessor
Sourcepub fn new(inner: OutcomeSegment) -> Self
pub fn new(inner: OutcomeSegment) -> Self
Wrap inner as a Tower service.
§Example
A Stopped outcome leaves the wrapper as Ok(ex) with CamelStop
forced to true, even though the incoming exchange carried
CamelStop = false:
use std::future::Future;
use std::pin::Pin;
use camel_api::{
Exchange, Message, OutcomePipeline, OutcomeSegment, PipelineOutcome, SegmentProcessor,
Value, is_camel_stop,
};
use tower::ServiceExt;
/// Always reports `Stopped`, leaving the exchange untouched.
#[derive(Clone)]
struct StoppedPipeline;
impl OutcomePipeline for StoppedPipeline {
fn clone_box(&self) -> Box<dyn OutcomePipeline> {
Box::new(self.clone())
}
fn run<'a>(
&'a mut self,
exchange: Exchange,
) -> Pin<Box<dyn Future<Output = PipelineOutcome> + Send + 'a>> {
Box::pin(async move { PipelineOutcome::Stopped(exchange) })
}
}
let mut exchange = Exchange::new(Message::new("x"));
exchange.set_property(camel_api::CAMEL_STOP, Value::Bool(false));
let processor = SegmentProcessor::new(OutcomeSegment::new(Box::new(StoppedPipeline)));
let response = ServiceExt::oneshot(processor, exchange)
.await
.expect("a stopped outcome is not an error");
assert!(
is_camel_stop(&response),
"the wrapper must force CamelStop=true"
);Trait Implementations§
Source§impl Clone for SegmentProcessor
impl Clone for SegmentProcessor
Source§impl Service<Exchange> for SegmentProcessor
impl Service<Exchange> for SegmentProcessor
Source§type Error = CamelError
type Error = CamelError
Errors produced by the service.
Source§type Future = Pin<Box<dyn Future<Output = Result<Exchange, CamelError>> + Send>>
type Future = Pin<Box<dyn Future<Output = Result<Exchange, CamelError>> + Send>>
The future response value.
Auto Trait Implementations§
impl !RefUnwindSafe for SegmentProcessor
impl !UnwindSafe for SegmentProcessor
impl Forget for SegmentProcessor
impl Freeze for SegmentProcessor
impl Move for SegmentProcessor
impl Send for SegmentProcessor
impl Sync for SegmentProcessor
impl Unpin for SegmentProcessor
impl UnsafeUnpin for SegmentProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<P> Processor for P
Source§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
Yields a mutable reference to the service when it is ready to accept a request.
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
Yields the service when it is ready to accept a request.
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
Consume this
Service, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
Executes a new future after this service’s future resolves. This does
not alter the behaviour of the
poll_ready method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
Maps this service’s response value to a different value. This does not
alter the behaviour of the
poll_ready method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
Maps this service’s error value to a different value. This does not
alter the behaviour of the
poll_ready method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Maps this service’s result type (
Result<Self::Response, Self::Error>)
to a different value, regardless of whether the future succeeds or
fails. Read moreSource§fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
Composes a function in front of the service. Read more
Source§fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
Composes an asynchronous function after this service. Read more
Source§fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
Composes a function that transforms futures produced by the service. Read more