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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Streaming types for server-streaming and client-streaming RPCs.
//!
//! # Server-Streaming Pattern
//!
//! For server-streaming RPCs, the server method returns a `Streaming<T>`:
//!
//! ```ignore
//! use rapace_core::Streaming;
//!
//! #[rapace::service]
//! trait RangeService {
//! async fn range(&self, n: u32) -> Streaming<u32>;
//! }
//! ```
//!
//! The macro generates:
//! - Server: Calls the method, iterates the stream, sends DATA frames, then EOS
//! - Client: An `async fn` that returns `Result<Streaming<T>, RpcError>`
//!
//! # Client Usage
//!
//! ```ignore
//! use futures::StreamExt;
//!
//! let mut stream = client.range(5).await?;
//! while let Some(item) = stream.next().await {
//! let value = item?;
//! println!("{}", value);
//! }
//! ```
//!
//! # Server Implementation
//!
//! ```ignore
//! use rapace_core::Streaming;
//!
//! impl RangeService for MyImpl {
//! async fn range(&self, n: u32) -> Streaming<u32> {
//! let (tx, rx) = tokio::sync::mpsc::channel(16);
//! tokio::spawn(async move {
//! for i in 0..n {
//! if tx.send(Ok(i)).await.is_err() {
//! break;
//! }
//! }
//! });
//! Box::pin(tokio_stream::wrappers::ReceiverStream::new(rx))
//! }
//! }
//! ```
use Future;
use Pin;
use crateRpcError;
/// Type alias for streaming RPC results.
///
/// Service traits should use this in their return types:
/// ```ignore
/// async fn range(&self, n: u32) -> Streaming<u32>;
/// ```
///
/// The outer `async fn` gives you the stream, and each item of the stream
/// is a `Result<T, RpcError>` representing either a value or an error.
pub type Streaming<T> = ;
/// A sink for sending streaming items from server to client.
///
/// This is an internal building block. For service trait definitions,
/// use `Streaming<T>` as the return type instead.
/// A source for receiving streaming items (used in client-streaming).
///
/// This is an internal building block for future client-streaming support.
/// Marker trait for types that can be streamed.
///
/// Types must implement `Facet<'static>` for serialization and be `Send`.
// Blanket implementation for all compatible types