pub struct Inbox { /* private fields */ }Expand description
The messages sent to a running turn, oldest first, bounded.
The server holds one per turn when steering is on
(RequestContext::inbox) and closes it
when the executor returns. An executor that never reads it is unaffected:
what is in it is dropped with the turn, and counted as unread.
Built directly (new) for an executor driven without a
server, as in a test; pass it to the context with
RequestContext::with_inbox.
use a2a_protocol_server::{Inbox, Steered};
use a2a_protocol_types::message::Message;
let inbox = Inbox::new(2);
let steered = Steered::new(Message::user_text("m-1", "use the cheaper index"), None);
inbox.try_push(steered.clone()).unwrap();
assert_eq!(inbox.try_recv(), Some(steered));
assert_eq!(inbox.try_recv(), None);Implementations§
Source§impl Inbox
impl Inbox
Sourcepub fn try_push(&self, steered: Steered) -> Result<(), Refused>
pub fn try_push(&self, steered: Steered) -> Result<(), Refused>
Adds steered at the end, waking a reader waiting in
recv. Never waits.
§Errors
Refused::Closed once the turn has ended, Refused::Full when the
inbox holds its capacity. Nothing is added then.
Sourcepub async fn recv(&self) -> Option<Steered>
pub async fn recv(&self) -> Option<Steered>
The oldest message, waiting for one to arrive; None once the turn
has ended and nothing is left. Safe to cancel: a message is taken only
when this returns it.
Sourcepub fn close(&self) -> usize
pub fn close(&self) -> usize
Ends the inbox: later pushes are refused as Refused::Closed, and a
reader waiting in recv is woken. What is already in it
can still be read. Returns how many messages were left unread.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Inbox
impl Forget for Inbox
impl Move for Inbox
impl RefUnwindSafe for Inbox
impl Send for Inbox
impl Sync for Inbox
impl Unpin for Inbox
impl UnsafeUnpin for Inbox
impl UnwindSafe for Inbox
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].