pub struct UserInputGate {
pub steering: Arc<SteeringInbox>,
/* private fields */
}Expand description
Mid-session user-input rendezvous.
When a loop wants to ask the user a question, it parks a oneshot sender here
and awaits the receiver; coder.respond takes the sender and fulfills it.
At most one request is pending at a time — a loop runs single-threaded, so
it cannot have two questions in flight, and coder.respond errors cleanly
when nothing is parked. The sender is dropped (which surfaces as a closed
channel to the waiter) if the session is cancelled or torn down before the
user answers.
Fields§
§steering: Arc<SteeringInbox>Implementations§
Source§impl UserInputGate
impl UserInputGate
pub fn new() -> Self
Sourcepub fn park(&self, prompt: &str) -> Receiver<String> ⓘ
pub fn park(&self, prompt: &str) -> Receiver<String> ⓘ
Park a fresh oneshot for a new question, returning the receiver the caller awaits. Any previously-parked (unanswered) sender is dropped, which closes its receiver — the prior waiter, if somehow still alive, then unblocks with an error rather than hanging forever.
Sourcepub fn pending_prompt(&self) -> Option<String>
pub fn pending_prompt(&self) -> Option<String>
The prompt of the currently-parked question, if any.
Sourcepub fn fulfill(&self, answer: String) -> Result<(), String>
pub fn fulfill(&self, answer: String) -> Result<(), String>
Fulfill the parked request with answer. Returns Err when nothing is
pending (so coder.respond can report “no pending request”) or when the
waiter has already gone away (cancelled/timed-out).
Sourcepub fn clear(&self)
pub fn clear(&self)
Drop any parked sender (cancellation/teardown): unblocks a waiter with a closed channel.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether a request is currently parked.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for UserInputGate
impl RefUnwindSafe for UserInputGate
impl Send for UserInputGate
impl Sync for UserInputGate
impl Unpin for UserInputGate
impl UnsafeUnpin for UserInputGate
impl UnwindSafe for UserInputGate
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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> ⓘ
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