1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! The macro-free typed path: a transport's wire items, typed by hand.
//!
//! A generated client builds its streams with [`MethodStream::call`] and
//! [`call_one`](crate::call_one). These are the same decoding for a caller
//! holding a raw [`ItemStream`] — a test, a tool that reads a stream the
//! macro did not generate a client for — with the item type spelled at the
//! call site:
//!
//! ```
//! use futures::TryStreamExt;
//! use plexus_client::{decode, MemoryTransport, MethodRef, Transport};
//!
//! #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
//! struct Tick { n: u32 }
//!
//! const COUNT: MethodRef = MethodRef::new("demo", "count");
//! let t = MemoryTransport::new().script_events(COUNT, &[Tick { n: 1 }, Tick { n: 2 }]);
//!
//! let ticks: Vec<Tick> = futures::executor::block_on(
//! decode::<Tick>(t.call(COUNT, serde_json::json!({}))).try_collect(),
//! )
//! .unwrap();
//! assert_eq!(ticks, vec![Tick { n: 1 }, Tick { n: 2 }]);
//! ```
//!
//! The decoding table is [`method_stream`](crate::method_stream)'s.
use DeserializeOwned;
use crateRawItem;
use crate;
use crate;
/// A transport's [`StreamItem`](crate::StreamItem)s as a typed call reads
/// them ([`RawItem`]s), each content the `Value` it carries.
/// [`decode`] on a typed call's items (PERF.115-36): each data item's
/// content decoded straight from the wire's JSON into `I`, never into a
/// `Value` first — what a generated client reads, on
/// [`Transport::call_raw`](crate::Transport::call_raw)'s items. A decode
/// error says what [`decode`] says of the same content.
/// A plain-`T` method's items: each data frame's `content` decodes as `I`;
/// progress frames are dropped. The stream's aggregate is `I` itself
/// ([`MethodStream::events`] yields the items).
/// [`decode`], opted in to progress: items as `Frame::Item(i)`, progress
/// frames decoded as `P` and yielded as `Frame::Progress(p)`, in arrival
/// order.
/// A Result method's items: each data frame's `content` is `{"ok": t}` or
/// `{"err": e}` ([`wire_result`](crate::wire_result)) and decodes as `Ok(t)`
/// / `Err(e)`. An `Err` is data — the activation saying no — so it does not
/// end the stream.