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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//! This library provides very *very* basic generic functions for building
//! quick and dirty interprocess or network protocols. Sewer metaphors
//! included.
//!
//! # Usage
//!
//! ```rust
//! use gutters::{pick_up, throw, hail, wait, throw_and_wait, pick_up_and_hail};
//!
//! // Here we use a TcpStream as a "gutter", but anything implementing
//! // Read and Write will do.
//! use std::net::TcpStream;
//! let mut stream = TcpStream::connect("127.0.0.1:34254");
//! // Of course, here you need a server on the other side.
//!
//! // You can "throw" data down the "gutter" with the corresponding
//! // function. The other side will have to "pick-up" the corresponding
//! // message (or "log", if you want to pursue the metaphor).
//! let log = 123.4f64
//! throw(&mut stream, &log)?;
//!
//! // You can "throw" as many "logs" as you want, while the other end
//! // "picks them up".
//! let log = 567.8f64
//! throw(&mut stream, &log)?;
//! throw(&mut stream, &log)?;
//!
//! // You can also "pick-up logs".
//! let mut log = 0.0f64;
//! pick_up(&mut stream, &mut log)?;
//! println!("{}", log)?;
//! pick_up(&mut stream, &mut log)?;
//! println!("{}", log)?;
//!
//! // If you need to synchronize with the other end, you can "hail" to
//! // them. They will have to "wait" for you.
//! hail(&mut stream)?;
//!
//! // You can also "wait" for the other end to "hail" you.
//! wait(&mut stream)?;
//!
//! // If you want to be synchronized with the other end at all time,
//! // you may use the `pick_up_and_hail` and `throw_and_wait` variants.
//! let log = 567.8f64
//! throw_and_wait(&mut stream, &log)?;
//!
//! let mut log = 0.0f64;
//! pick_up_and_hail(&mut stream, &mut log)?;
//! println!("{}", log)?;
//! ```
use ;
/// Read a message of type `T` from the `gutter`.
///
/// This function is blocking.
///
/// This function doesn't change endianness, so it must be the
/// same between the peers.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// let mut data = 0.0f64
/// pick_up(&mut stream, &mut data)?;
/// ```
/// Send a message of type `T` to the `gutter`.
///
/// This function is blocking.
///
/// This function doesn't change endianness, so it must be the
/// same between the peers.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// throw(&mut stream, &64.0)?;
/// ```
/// Send an acknowledgment to the `gutter`.
///
/// This function is blocking.
///
/// The acknowledgment is a single byte `b'\n'`.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// hail(&mut stream)?;
/// ```
/// Wait for an acknowledgment from the `gutter`.
///
/// This function is blocking.
///
/// The exact byte value of the acknowledgment is *not* checked for.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// wait(&mut stream)?;
/// ```
/// Read a message of type `T` from the `gutter`, and send an
/// acknowledgement.
///
/// Equivalent to calling [`pick_up`] and then [`hail`].
///
/// This function is blocking.
///
/// This function doesn't change endianness, so it must be the
/// same between the peers.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// let mut data = 0.0f64
/// pick_up_and_hail(&mut stream, &mut data)?;
/// ```
/// Send a message of type `T` to the `gutter`, and wait for an
/// acknowledgement.
///
/// Equivalent to calling [`throw`] and then [`wait`].
///
/// This function is blocking.
///
/// This function doesn't change endianness, so it must be the
/// same between the peers.
///
/// # Examples
///
/// Basic usage:
///
/// ```no_run
/// use std::net::TcpStream;
/// let stream = TcpStream::connect("127.0.0.1:34567")
///
/// throw(&mut stream, &64.0)?;
/// ```