plexus_client/method_stream.rs
1//! What a many-item method's client call returns: [`MethodStream`].
2//!
3//! A method that yields many items (`-> impl Stream<Item = …>`) is called as
4//! a stream of its items — a plain
5//! `TryStream<Ok = I, Error = ClientError>` — and two per-call opt-ins turn
6//! that same call into something else (RETURNS-1 decisions 6, 11):
7//!
8//! | Call | Yields | Progress frames |
9//! |---|---|---|
10//! | `client.m(..)` | `Result<I, ClientError>` | dropped, undecoded |
11//! | `client.m(..).with_progress()` | `Result<Frame<I, P>, ClientError>`, in arrival order | decoded as `P` |
12//! | `client.m(..).events()` | `Result<{Ns}Event, ClientError>`, `{Ns}Event::M(item)` | dropped |
13//!
14//! `I` is the method's item — a plain `T`, or a `Result<T, E>` decoded from
15//! its `{"ok"}` / `{"err"}` wire form — `P` its progress type ([`NoProgress`]
16//! when it declares none) and `A` the activation's `{Ns}Event` aggregate.
17//!
18//! # Decoding, exhaustively
19//!
20//! | Wire item | Yielded | Stream continues? |
21//! |---|---|---|
22//! | `data` (decodes as `I`) | the item | yes |
23//! | `data` (does not) | `Err(ClientError::Decode)` | **no** |
24//! | `progress` | nothing — unless opted in: `Frame::Progress(p)` | yes |
25//! | `progress` (opted in, does not decode as `P`) | `Err(ClientError::Decode)` | **no** |
26//! | `error` | `Err(ClientError::Remote(RemoteError))` | **no** |
27//! | any other `type` (spec/03) | *skipped* | yes |
28//! | `done` | nothing | **no** |
29//! | transport failure | `Err(ClientError::Transport)` | **no** |
30//!
31//! A failed call stays an *item* of the stream, so a cut-off stream cannot
32//! pass for a finished one. An `err` item (`Err(e)` of a Result method) is
33//! data, the activation saying no: it is `Ok(Err(e))` here and does not end
34//! the stream — the method decides whether more follows.
35//!
36//! [`NoProgress`] is uninhabited, so `.with_progress()` exists on every
37//! many-item method and still never yields a progress frame where the schema
38//! declares none: such a frame cannot decode, and is a contract break like
39//! any other.
40
41use std::fmt;
42use std::marker::PhantomData;
43use std::pin::Pin;
44use std::task::{Context, Poll};
45
46use futures_core::{FusedStream, Stream};
47use serde::de::{self, DeserializeOwned, Deserializer};
48use serde::{Deserialize, Serialize, Serializer};
49use serde_json::Value;
50
51use crate::envelope::{Content, RawItem};
52use crate::error::ClientError;
53use crate::frame::Frame;
54use crate::lift::{Lift, Root};
55use crate::transport::{InputItems, MethodRef, RawItemStream, Transport};
56
57/// Decodes one data frame's `content` into a method's item `I` — straight
58/// from the wire's text where the transport kept it (PERF.115-36's
59/// [`Content`]), never through a `Value` first.
60///
61/// A plain-`T` method's is `Content::decode::<T>`; a Result method's is
62/// [`wire_result::from_content::<T, E>`](crate::wire_result::from_content),
63/// which reads `{"ok"}` / `{"err"}`. A function pointer, so it is `Send`,
64/// `Sync` and `Copy` whatever `I` is.
65pub type Decoder<I> = fn(Content) -> Result<I, serde_json::Error>;
66
67/// The progress type of a method that reports none. Uninhabited: no value of
68/// it exists, so a stream typed `Frame<I, NoProgress>` can only ever yield
69/// items.
70///
71/// It deserializes from nothing — a progress frame for a method whose schema
72/// declares no progress is a contract break, reported as
73/// [`ClientError::Decode`] under `.with_progress()` (and dropped undecoded
74/// without it, as every progress frame is).
75#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
76pub enum NoProgress {}
77
78impl Serialize for NoProgress {
79 fn serialize<S: Serializer>(&self, _: S) -> Result<S::Ok, S::Error> {
80 match *self {}
81 }
82}
83
84impl<'de> Deserialize<'de> for NoProgress {
85 fn deserialize<D: Deserializer<'de>>(_: D) -> Result<Self, D::Error> {
86 Err(de::Error::custom(
87 "a progress frame for a method that declares no progress",
88 ))
89 }
90}
91
92/// The wire items behind a typed stream, and where they stand.
93enum State<'a> {
94 /// Items still arriving.
95 Live(RawItemStream<'a>),
96 /// The call failed before anything was sent (a parameter that would not
97 /// encode); yielded once, then finished.
98 Failed(ClientError),
99 /// A terminal item was seen (or yielded). The wire stream is dropped the
100 /// moment this is reached, so a transport that cancels on drop (the
101 /// WebSocket one) cancels exactly the calls the client gave up on.
102 Finished,
103}
104
105/// The decoding shared by [`MethodStream`] and [`WithProgress`].
106struct Core<'a, I> {
107 state: State<'a>,
108 item: Decoder<I>,
109}
110
111impl<'a, I> Core<'a, I> {
112 fn new(state: State<'a>, item: Decoder<I>) -> Self {
113 Self { state, item }
114 }
115
116 /// The next frame. `progress` is `None` to drop progress frames
117 /// undecoded, `Some(decoder)` to yield them.
118 fn poll_frame<P>(
119 &mut self,
120 cx: &mut Context<'_>,
121 progress: Option<Decoder<P>>,
122 ) -> Poll<Option<Result<Frame<I, P>, ClientError>>> {
123 loop {
124 let next = match &mut self.state {
125 State::Live(items) => match items.as_mut().poll_next(cx) {
126 Poll::Pending => return Poll::Pending,
127 Poll::Ready(next) => next,
128 },
129 State::Failed(_) => {
130 let State::Failed(e) = std::mem::replace(&mut self.state, State::Finished)
131 else {
132 unreachable!("matched Failed above")
133 };
134 return Poll::Ready(Some(Err(e)));
135 }
136 State::Finished => return Poll::Ready(None),
137 };
138
139 let (out, terminal) = match next {
140 // Normal completion is the stream ending; a `done` is not an
141 // item. A transport that ends without one has said all it
142 // will say.
143 None | Some(Ok(RawItem::Done)) => {
144 self.state = State::Finished;
145 return Poll::Ready(None);
146 }
147 Some(Err(e)) => (Err(ClientError::Transport(e)), true),
148 Some(Ok(RawItem::Error { error, .. })) => (Err(ClientError::Remote(*error)), true),
149 Some(Ok(RawItem::Data { content, content_type })) => match (self.item)(content) {
150 Ok(item) => (Ok(Frame::Item(item)), false),
151 Err(e) => (
152 Err(ClientError::Decode {
153 content_type: content_type.map(|c| c.to_string()),
154 message: message_of(&e),
155 }),
156 true,
157 ),
158 },
159 Some(Ok(RawItem::Progress { content, content_type })) => match progress {
160 None => continue,
161 Some(decode) => match decode(content) {
162 Ok(p) => (Ok(Frame::Progress(p)), false),
163 Err(e) => (
164 Err(ClientError::Decode {
165 content_type: content_type.map(|c| c.to_string()),
166 message: format!("progress: {}", message_of(&e)),
167 }),
168 true,
169 ),
170 },
171 },
172 };
173 if terminal {
174 self.state = State::Finished;
175 }
176 return Poll::Ready(Some(out));
177 }
178 }
179
180 fn is_terminated(&self) -> bool {
181 matches!(self.state, State::Finished)
182 }
183
184 fn state_name(&self) -> &'static str {
185 match self.state {
186 State::Live(_) => "live",
187 State::Failed(_) => "failed",
188 State::Finished => "finished",
189 }
190 }
191}
192
193fn identity<T>(t: T) -> T {
194 t
195}
196
197/// A decode error as a `Value`'s decode words it: serde_json's message,
198/// without the position a decode from text adds (PERF.115-36).
199fn message_of(e: &serde_json::Error) -> String {
200 let message = e.to_string();
201 if e.line() == 0 {
202 return message;
203 }
204 let at = format!(" at line {} column {}", e.line(), e.column());
205 match message.strip_suffix(&at) {
206 Some(bare) => bare.to_owned(),
207 None => message,
208 }
209}
210
211/// One call of a many-item method: a stream of its items.
212///
213/// `I` is the item, `P` the progress type ([`NoProgress`] when the method
214/// declares none), `A` the activation's `{Ns}Event` aggregate. A generated
215/// client spells all four — `MethodStream<'_, Result<Row, ScanError>,
216/// NoProgress, TicketsEvent>`; the defaults are for the macro-free
217/// [`decode`](crate::decode) path.
218///
219/// It is a plain `Stream<Item = Result<I, ClientError>>` — a `TryStream` —
220/// so `futures`' combinators apply:
221///
222/// ```ignore
223/// use futures::TryStreamExt;
224/// let rows: Vec<Result<Row, ScanError>> = client.scan("a".into()).try_collect().await?;
225/// ```
226///
227/// Progress frames are dropped undecoded unless the caller opts in with
228/// [`with_progress`](Self::with_progress); [`events`](Self::events) turns
229/// the call into the activation's aggregate. See the [module docs](self)
230/// for the decoding table.
231///
232/// `Unpin`, and `Send` wherever the transport's item stream is (everywhere
233/// but wasm32); dropping it mid-stream drops the wire stream, which cancels
234/// the call on a transport that can (the WebSocket one unsubscribes).
235/// How an item becomes its activation's aggregate: the method's variant.
236///
237/// A `fn(I) -> A` is one (`TicketsEvent::List`). The activation macro emits a
238/// zero-sized one per many-item method (RETURNS-46), so the variant and the
239/// lift above it are one inlined step per event — not a call through a
240/// pointer and then the lift, which costs about 10 ns an event.
241pub trait EventOf<I> {
242 /// The activation's aggregate.
243 type Aggregate;
244 /// `item` as its aggregate.
245 fn event(&self, item: I) -> Self::Aggregate;
246}
247
248impl<I, A> EventOf<I> for fn(I) -> A {
249 type Aggregate = A;
250 #[inline]
251 fn event(&self, item: I) -> A {
252 self(item)
253 }
254}
255
256pub struct MethodStream<'a, I, P = NoProgress, A = I, L = Root, W = fn(I) -> A> {
257 core: Core<'a, I>,
258 /// An item as the activation's aggregate: the method's variant.
259 event: W,
260 _aggregate: PhantomData<fn() -> A>,
261 /// RETURNS-46: the aggregate as the client's — [`Root`] for a client
262 /// reached through nothing, a parent's wrapping for one an accessor made.
263 lift: L,
264 _progress: PhantomData<fn() -> P>,
265}
266
267impl<'a, I, P, A> MethodStream<'a, I, P, A> {
268 /// Type a transport's wire items as one method's stream: `item` decodes
269 /// each data frame's `content`, `event` wraps an item in the
270 /// aggregate (`TicketsEvent::List`) for [`events`](Self::events).
271 pub fn new(items: RawItemStream<'a>, item: Decoder<I>, event: fn(I) -> A) -> Self {
272 Self::from_core(Core::new(State::Live(items), item), event)
273 }
274
275 /// Call `method` on `transport` with `params` and type the answer — what
276 /// a generated client's many-item method is. When `params` is an `Err`
277 /// (an argument that would not encode) nothing is sent and the stream
278 /// yields that error once.
279 pub fn call<T>(
280 transport: &'a T,
281 method: MethodRef,
282 params: Result<Value, ClientError>,
283 item: Decoder<I>,
284 event: fn(I) -> A,
285 ) -> Self
286 where
287 T: Transport + ?Sized,
288 {
289 let state = match params {
290 // PERF.115-36: the items with their content still the wire's
291 // text, decoded straight into the item.
292 Ok(params) => State::Live(transport.call_raw(method, params)),
293 Err(e) => State::Failed(e),
294 };
295 Self::from_core(Core::new(state, item), event)
296 }
297
298 /// BIDIR-6: [`call`](Self::call), for a method with an input half:
299 /// `input` is sent under the callee's credit as the stream is read.
300 pub fn call_with_input<T>(
301 transport: &'a T,
302 method: MethodRef,
303 params: Result<Value, ClientError>,
304 input: InputItems<'a>,
305 item: Decoder<I>,
306 event: fn(I) -> A,
307 ) -> Self
308 where
309 T: Transport + ?Sized,
310 {
311 let state = match params {
312 Ok(params) => State::Live(transport.call_raw_with_input(method, params, input)),
313 Err(e) => State::Failed(e),
314 };
315 Self::from_core(Core::new(state, item), event)
316 }
317
318 fn from_core(core: Core<'a, I>, event: fn(I) -> A) -> Self {
319 Self {
320 core,
321 event,
322 _aggregate: PhantomData,
323 lift: Root,
324 _progress: PhantomData,
325 }
326 }
327
328 /// [`call`](Self::call) with the method's variant as an [`EventOf`] —
329 /// what a generated client passes (RETURNS-46): a zero-sized type, so
330 /// the variant inlines into [`events`](Self::events).
331 pub fn call_as<T, W>(
332 transport: &'a T,
333 method: MethodRef,
334 params: Result<Value, ClientError>,
335 item: Decoder<I>,
336 event: W,
337 ) -> MethodStream<'a, I, P, A, Root, W>
338 where
339 T: Transport + ?Sized,
340 W: EventOf<I, Aggregate = A>,
341 {
342 let state = match params {
343 Ok(params) => State::Live(transport.call_raw(method, params)),
344 Err(e) => State::Failed(e),
345 };
346 MethodStream {
347 core: Core::new(state, item),
348 event,
349 _aggregate: PhantomData,
350 lift: Root,
351 _progress: PhantomData,
352 }
353 }
354}
355
356impl<'a, I, P, A> MethodStream<'a, I, P, A> {
357 /// [`call_as`](Self::call_as) for a method with an input half
358 /// (BIDIR-6, RETURNS-46): `input` is sent under the callee's credit as
359 /// the stream is read.
360 pub fn call_as_with_input<T, W>(
361 transport: &'a T,
362 method: MethodRef,
363 params: Result<Value, ClientError>,
364 input: InputItems<'a>,
365 item: Decoder<I>,
366 event: W,
367 ) -> MethodStream<'a, I, P, A, Root, W>
368 where
369 T: Transport + ?Sized,
370 W: EventOf<I, Aggregate = A>,
371 {
372 let state = match params {
373 Ok(params) => State::Live(transport.call_raw_with_input(method, params, input)),
374 Err(e) => State::Failed(e),
375 };
376 MethodStream {
377 core: Core::new(state, item),
378 event,
379 _aggregate: PhantomData,
380 lift: Root,
381 _progress: PhantomData,
382 }
383 }
384}
385
386impl<'a, I, P, A, L, W> MethodStream<'a, I, P, A, L, W> {
387 /// RETURNS-46: the same call, its [`events`](Self::events) lifted by
388 /// `lift` into an enclosing aggregate — what a client reached through a
389 /// parent's accessor does with every many-item call, so the call's
390 /// events are the parent's (`TreeEvent::Branch(BranchEvent::Grow(..))`).
391 pub fn lifted<L2: Lift<A>>(self, lift: L2) -> MethodStream<'a, I, P, A, L2, W> {
392 MethodStream {
393 core: self.core,
394 event: self.event,
395 _aggregate: PhantomData,
396 lift,
397 _progress: PhantomData,
398 }
399 }
400
401 /// Opt in to progress: the same call, yielding each item as
402 /// [`Frame::Item`] and each progress frame, decoded as `P`, as
403 /// [`Frame::Progress`] — in arrival order.
404 ///
405 /// For a method that declares no progress `P` is [`NoProgress`], and the
406 /// stream yields only items.
407 pub fn with_progress(self) -> WithProgress<'a, I, P>
408 where
409 P: DeserializeOwned,
410 {
411 WithProgress {
412 core: self.core,
413 _progress: PhantomData,
414 }
415 }
416
417 /// The same call as the activation's aggregate: each item `i` becomes
418 /// `{Ns}Event::M(i)`; progress is dropped (the aggregate carries items
419 /// only). Every method's `events()` has the same type, so several calls
420 /// merge into one listener with ordinary stream plumbing:
421 ///
422 /// ```ignore
423 /// let mut all = futures::stream::select_all([
424 /// client.watch(None).events(),
425 /// client.list(None, None).events(),
426 /// ]);
427 /// while let Some(ev) = all.next().await { state.reduce(ev?) } // ev: TicketsEvent
428 /// ```
429 pub fn events(self) -> Events<'a, L::Out>
430 where
431 L: Lift<A>,
432 W: EventOf<I, Aggregate = A> + Clone + MaybeSendSync + 'a,
433 I: 'a,
434 P: 'a,
435 A: 'a,
436 L::Out: 'a,
437 {
438 let event = self.event.clone();
439 let lift = self.lift.clone();
440 Events {
441 inner: Box::pin(futures_util::StreamExt::map(self, move |r| r.map(|i| lift.lift(event.event(i))))),
442 }
443 }
444}
445
446/// `Send + Sync` off wasm32, nothing on it — what an event constructor
447/// moved into a boxed [`Events`] must be.
448#[cfg(not(target_arch = "wasm32"))]
449pub trait MaybeSendSync: Send + Sync {}
450#[cfg(not(target_arch = "wasm32"))]
451impl<T: Send + Sync> MaybeSendSync for T {}
452/// See the non-wasm32 variant.
453#[cfg(target_arch = "wasm32")]
454pub trait MaybeSendSync {}
455#[cfg(target_arch = "wasm32")]
456impl<T> MaybeSendSync for T {}
457
458// No field is pinned: the wire stream is boxed, the lift a plain value.
459impl<I, P, A, L, W> Unpin for MethodStream<'_, I, P, A, L, W> {}
460
461impl<I, P, A, L, W> Stream for MethodStream<'_, I, P, A, L, W> {
462 type Item = Result<I, ClientError>;
463
464 #[inline]
465 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
466 self.get_mut()
467 .core
468 .poll_frame::<NoProgress>(cx, None)
469 .map(|next| {
470 next.map(|frame| {
471 frame.map(|frame| match frame {
472 Frame::Item(item) => item,
473 Frame::Progress(never) => match never {},
474 })
475 })
476 })
477 }
478}
479
480impl<I, P, A, L, W> FusedStream for MethodStream<'_, I, P, A, L, W> {
481 fn is_terminated(&self) -> bool {
482 self.core.is_terminated()
483 }
484}
485
486impl<I, P, A, L, W> fmt::Debug for MethodStream<'_, I, P, A, L, W> {
487 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
488 f.debug_struct("MethodStream")
489 .field("state", &self.core.state_name())
490 .finish_non_exhaustive()
491 }
492}
493
494/// A [`MethodStream`] whose caller opted in to progress
495/// ([`MethodStream::with_progress`]): `Result<Frame<I, P>, ClientError>`,
496/// in arrival order.
497pub struct WithProgress<'a, I, P> {
498 core: Core<'a, I>,
499 _progress: PhantomData<fn() -> P>,
500}
501
502impl<I, P: DeserializeOwned> Stream for WithProgress<'_, I, P> {
503 type Item = Result<Frame<I, P>, ClientError>;
504
505 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
506 self.get_mut()
507 .core
508 .poll_frame(cx, Some(Content::decode::<P> as Decoder<P>))
509 }
510}
511
512impl<I, P: DeserializeOwned> FusedStream for WithProgress<'_, I, P> {
513 fn is_terminated(&self) -> bool {
514 self.core.is_terminated()
515 }
516}
517
518impl<I, P> fmt::Debug for WithProgress<'_, I, P> {
519 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
520 f.debug_struct("WithProgress")
521 .field("state", &self.core.state_name())
522 .finish_non_exhaustive()
523 }
524}
525
526#[cfg(not(target_arch = "wasm32"))]
527type BoxedEvents<'a, A> = Pin<Box<dyn FusedStream<Item = Result<A, ClientError>> + Send + 'a>>;
528
529#[cfg(target_arch = "wasm32")]
530type BoxedEvents<'a, A> = Pin<Box<dyn FusedStream<Item = Result<A, ClientError>> + 'a>>;
531
532/// A call as the activation's aggregate ([`MethodStream::events`]):
533/// `Result<A, ClientError>`, where `A` is `{Ns}Event`.
534///
535/// Its type names only the aggregate, not the method, so every method's
536/// `events()` is the same type and several calls merge with
537/// `futures::stream::select_all` (or `select`). Mirrors the transport's
538/// `Send` bound: `Send` off wasm32, not on it.
539pub struct Events<'a, A> {
540 inner: BoxedEvents<'a, A>,
541}
542
543impl<A> Stream for Events<'_, A> {
544 type Item = Result<A, ClientError>;
545
546 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
547 self.inner.as_mut().poll_next(cx)
548 }
549
550 fn size_hint(&self) -> (usize, Option<usize>) {
551 self.inner.size_hint()
552 }
553}
554
555impl<A> FusedStream for Events<'_, A> {
556 fn is_terminated(&self) -> bool {
557 self.inner.is_terminated()
558 }
559}
560
561impl<A> fmt::Debug for Events<'_, A> {
562 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
563 f.debug_struct("Events")
564 .field("terminated", &self.inner.is_terminated())
565 .finish_non_exhaustive()
566 }
567}
568
569/// Call a one-item method (`-> T`, `-> Result<T, E>`) and return its item —
570/// what a generated client's one-item `async fn` is.
571///
572/// Reads the call to its terminal frame: one data item, then `done`. So a
573/// transport that cancels a dropped call (the WebSocket one) never cancels a
574/// call that finished, and a server that breaks the contract is caught:
575///
576/// | Wire | Result |
577/// |---|---|
578/// | one `data` (decodes), `done` | `Ok(item)` |
579/// | `error` (before or after the item) | `Err(ClientError::Remote)` |
580/// | `done` with no item, or a second item | `Err(ClientError::Decode)` naming the method |
581/// | transport failure | `Err(ClientError::Transport)` |
582///
583/// Progress frames are dropped (a one-item method never reports progress:
584/// RETURNS-1 decision 10). When `params` is an
585/// `Err` nothing is sent and that is the result.
586pub async fn call_one<T, I>(
587 transport: &T,
588 method: MethodRef,
589 params: Result<Value, ClientError>,
590 item: Decoder<I>,
591) -> Result<I, ClientError>
592where
593 T: Transport + ?Sized,
594{
595 let qualified = method.qualified();
596 one_of(MethodStream::call(transport, method, params, item, identity::<I>), qualified).await
597}
598
599/// BIDIR-6: [`call_one`], for a method with an input half: `input` is sent
600/// under the callee's credit while the call is read to its end.
601pub async fn call_one_with_input<'a, T, I>(
602 transport: &'a T,
603 method: MethodRef,
604 params: Result<Value, ClientError>,
605 input: InputItems<'a>,
606 item: Decoder<I>,
607) -> Result<I, ClientError>
608where
609 T: Transport + ?Sized,
610{
611 let qualified = method.qualified();
612 one_of(MethodStream::call_with_input(transport, method, params, input, item, identity::<I>), qualified).await
613}
614
615/// A one-item call's item, read to its terminal frame. `qualified` names
616/// the method in a contract break (RETURNS-46: a `MethodRef` is `Clone`, not
617/// `Copy`, so the name is taken before the call has it).
618async fn one_of<I>(mut items: MethodStream<'_, I>, qualified: String) -> Result<I, ClientError> {
619 use futures_util::StreamExt;
620
621 let contract = |message: &str| ClientError::Decode {
622 content_type: Some(qualified.clone()),
623 message: message.to_string(),
624 };
625 let first = match items.next().await {
626 Some(first) => first?,
627 None => return Err(contract("a one-item method ended without its item")),
628 };
629 match items.next().await {
630 None => Ok(first),
631 Some(Err(e)) => Err(e),
632 Some(Ok(_)) => Err(contract("a one-item method sent more than one item")),
633 }
634}
635
636/// The `Decoder` for a plain item, as a function pointer.
637pub(crate) fn plain<I: DeserializeOwned>() -> Decoder<I> {
638 Content::decode::<I>
639}
640
641/// `MethodStream::new` with the identity aggregate, for the macro-free path.
642pub(crate) fn untagged<'a, I>(items: RawItemStream<'a>, item: Decoder<I>) -> MethodStream<'a, I> {
643 MethodStream::new(items, item, identity::<I>)
644}
645
646#[cfg(test)]
647mod tests {
648 use super::*;
649
650 #[test]
651 fn no_progress_never_deserializes() {
652 let err = serde_json::from_value::<NoProgress>(serde_json::json!({"message": "x"}))
653 .unwrap_err();
654 assert!(err.to_string().contains("declares no progress"), "{err}");
655 }
656
657 #[test]
658 fn method_streams_are_send_and_unpin() {
659 fn send_unpin<T: Send + Unpin>() {}
660 send_unpin::<MethodStream<'static, String, NoProgress, u8>>();
661 send_unpin::<WithProgress<'static, String, crate::Note>>();
662 send_unpin::<Events<'static, u8>>();
663 }
664}