Skip to content

Commit eec45e6

Browse files
djcRalith
authored andcommitted
book: fix example code
1 parent 41f7d2e commit eec45e6

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ categories.workspace = true
1010

1111
[dependencies]
1212
anyhow.workspace = true
13+
bytes = { workspace = true }
1314
quinn = { version = "0.11.7", path = "../../quinn" }
1415
rcgen.workspace = true
1516
rustls.workspace = true

docs/book/src/quinn/data-transfer.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1+
use bytes::Bytes;
12
use quinn::Connection;
23

34
async fn open_bidirectional_stream(connection: Connection) -> anyhow::Result<()> {
4-
let (mut send, recv) = connection.open_bi().await?;
5+
let (mut send, mut recv) = connection.open_bi().await?;
56
send.write_all(b"test").await?;
6-
send.finish().await?;
7+
send.finish()?;
78
let received = recv.read_to_end(10).await?;
89
Ok(())
910
}
1011

1112
async fn receive_bidirectional_stream(connection: Connection) -> anyhow::Result<()> {
12-
while let Ok((mut send, recv)) = connection.accept_bi().await {
13+
while let Ok((mut send, mut recv)) = connection.accept_bi().await {
1314
// Because it is a bidirectional stream, we can both send and receive.
1415
println!("request: {:?}", recv.read_to_end(50).await?);
1516
send.write_all(b"response").await?;
16-
send.finish().await?;
17+
send.finish()?;
1718
}
1819
Ok(())
1920
}
2021

2122
async fn open_unidirectional_stream(connection: Connection) -> anyhow::Result<()> {
2223
let mut send = connection.open_uni().await?;
2324
send.write_all(b"test").await?;
24-
send.finish().await?;
25+
send.finish()?;
2526
Ok(())
2627
}
2728

2829
async fn receive_unidirectional_stream(connection: Connection) -> anyhow::Result<()> {
29-
while let Ok(recv) = connection.accept_uni().await {
30+
while let Ok(mut recv) = connection.accept_uni().await {
3031
// Because it is a unidirectional stream, we can only receive not send back.
3132
println!("{:?}", recv.read_to_end(50).await?);
3233
}
3334
Ok(())
3435
}
3536

3637
async fn send_unreliable(connection: Connection) -> anyhow::Result<()> {
37-
connection.send_datagram(b"test".into()).await?;
38+
connection.send_datagram(Bytes::from(&b"test"[..]))?;
3839
Ok(())
3940
}
4041

docs/book/src/quinn/set-up-connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn server(config: ServerConfig) -> Result<(), Box<dyn Error>> {
2828

2929
async fn client() -> Result<(), Box<dyn Error>> {
3030
// Bind this endpoint to a UDP socket on the given client address.
31-
let mut endpoint = Endpoint::client(client_addr());
31+
let mut endpoint = Endpoint::client(client_addr())?;
3232

3333
// Connect to the server passing in the server name which is supposed to be in the server certificate.
3434
let connection = endpoint.connect(server_addr(), SERVER_NAME)?.await?;

0 commit comments

Comments
 (0)