Skip to content

Commit 3610629

Browse files
djcRalith
authored andcommitted
book: suppress warnings in code samples
1 parent 3d019b3 commit 3610629

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

docs/book/src/quinn/certificate-certs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn generate_self_signed_cert() -> Result<
3030
Ok((cert_der, key))
3131
}
3232

33+
#[allow(unused_variables)]
3334
fn main() {
3435
let (self_signed_certs, self_signed_key) = generate_self_signed_cert().unwrap();
3536
let (certs, key) = read_certs_from_file().unwrap();

docs/book/src/quinn/certificate-insecure.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl rustls::client::danger::ServerCertVerifier for SkipServerVerification {
5959
}
6060
}
6161

62+
#[allow(dead_code)] // Included in `certificate.md`
6263
fn configure_client() -> Result<ClientConfig, NoInitialCipherSuite> {
6364
let crypto = rustls::ClientConfig::builder()
6465
.dangerous()
@@ -70,6 +71,4 @@ fn configure_client() -> Result<ClientConfig, NoInitialCipherSuite> {
7071
)?)))
7172
}
7273

73-
fn main() {
74-
let client_config = configure_client().unwrap();
75-
}
74+
fn main() {}

docs/book/src/quinn/certificate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Then, allow the client to skip the certificate validation by implementing [Serve
2525
After that, modify the [ClientConfig][ClientConfig] to use this [ServerCertVerifier][ServerCertVerifier] implementation.
2626

2727
```rust
28-
{{#include certificate-insecure.rs:62:71}}
28+
{{#include certificate-insecure.rs:63:72}}
2929
```
3030

3131
Finally, if you plug this [ClientConfig][ClientConfig] into the [Endpoint::set_default_client_config()][set_default_client_config] your client endpoint should verify all connections as trustworthy.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ For example, from the connection initiator to the peer and the other way around.
3434
*open bidirectional stream*
3535

3636
```rust
37-
{{#include data-transfer.rs:4:10}}
37+
{{#include data-transfer.rs:5:11}}
3838
```
3939

4040
*iterate incoming bidirectional stream(s)*
4141

4242
```rust
43-
{{#include data-transfer.rs:12:20}}
43+
{{#include data-transfer.rs:14:22}}
4444
```
4545

4646
## Unidirectional Streams
@@ -51,13 +51,13 @@ It is possible to get reliability without ordering (so no head-of-line blocking)
5151
*open unidirectional stream*
5252

5353
```rust
54-
{{#include data-transfer.rs:22:27}}
54+
{{#include data-transfer.rs:25:30}}
5555
```
5656

5757
*iterating incoming unidirectional stream(s)*
5858

5959
```rust
60-
{{#include data-transfer.rs:29:35}}
60+
{{#include data-transfer.rs:33:39}}
6161
```
6262

6363
## Unreliable Messaging
@@ -68,13 +68,13 @@ This could be useful if data arrival isn't essential or when high throughput is
6868
*send datagram*
6969

7070
```rust
71-
{{#include data-transfer.rs:37:40}}
71+
{{#include data-transfer.rs:42:45}}
7272
```
7373

7474
*iterating datagram stream(s)*
7575

7676
```rust
77-
{{#include data-transfer.rs:42:48}}
77+
{{#include data-transfer.rs:48:54}}
7878
```
7979

8080
[Endpoint]: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bytes::Bytes;
22
use quinn::Connection;
33

4+
#[allow(dead_code, unused_variables)] // Included in `data-transfer.md`
45
async fn open_bidirectional_stream(connection: Connection) -> anyhow::Result<()> {
56
let (mut send, mut recv) = connection.open_bi().await?;
67
send.write_all(b"test").await?;
@@ -9,6 +10,7 @@ async fn open_bidirectional_stream(connection: Connection) -> anyhow::Result<()>
910
Ok(())
1011
}
1112

13+
#[allow(dead_code)] // Included in `data-transfer.md`
1214
async fn receive_bidirectional_stream(connection: Connection) -> anyhow::Result<()> {
1315
while let Ok((mut send, mut recv)) = connection.accept_bi().await {
1416
// Because it is a bidirectional stream, we can both send and receive.
@@ -19,13 +21,15 @@ async fn receive_bidirectional_stream(connection: Connection) -> anyhow::Result<
1921
Ok(())
2022
}
2123

24+
#[allow(dead_code)] // Included in `data-transfer.md`
2225
async fn open_unidirectional_stream(connection: Connection) -> anyhow::Result<()> {
2326
let mut send = connection.open_uni().await?;
2427
send.write_all(b"test").await?;
2528
send.finish()?;
2629
Ok(())
2730
}
2831

32+
#[allow(dead_code)] // Included in `data-transfer.md`
2933
async fn receive_unidirectional_stream(connection: Connection) -> anyhow::Result<()> {
3034
while let Ok(mut recv) = connection.accept_uni().await {
3135
// Because it is a unidirectional stream, we can only receive not send back.
@@ -34,15 +38,19 @@ async fn receive_unidirectional_stream(connection: Connection) -> anyhow::Result
3438
Ok(())
3539
}
3640

41+
#[allow(dead_code)] // Included in `data-transfer.md`
3742
async fn send_unreliable(connection: Connection) -> anyhow::Result<()> {
3843
connection.send_datagram(Bytes::from(&b"test"[..]))?;
3944
Ok(())
4045
}
4146

47+
#[allow(dead_code)] // Included in `data-transfer.md`
4248
async fn receive_datagram(connection: Connection) -> anyhow::Result<()> {
4349
while let Ok(received_bytes) = connection.read_datagram().await {
4450
// Because it is a unidirectional stream, we can only receive not send back.
4551
println!("request: {:?}", received_bytes);
4652
}
4753
Ok(())
4854
}
55+
56+
fn main() {}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The [server()][server] method, which can be used for this, returns the `Endpoint
2222
`Endpoint` is used to start outgoing connections and accept incoming connections.
2323

2424
```rust
25-
{{#include set-up-connection.rs:15:27}}
25+
{{#include set-up-connection.rs:16:28}}
2626
```
2727

2828
**Client**
@@ -32,7 +32,7 @@ The client needs to connect to the server using the [connect(server_name)][conne
3232
The `SERVER_NAME` argument is the DNS name, matching the certificate configured in the server.
3333

3434
```rust
35-
{{#include set-up-connection.rs:29:39}}
35+
{{#include set-up-connection.rs:31:41}}
3636
```
3737
<br><hr>
3838

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ fn server_addr() -> SocketAddr {
1212
"127.0.0.1:5001".parse::<SocketAddr>().unwrap()
1313
}
1414

15+
#[allow(dead_code, unused_variables)] // Included in `set-up-connection.md`
1516
async fn server(config: ServerConfig) -> Result<(), Box<dyn Error>> {
1617
// Bind this endpoint to a UDP socket on the given server address.
1718
let endpoint = Endpoint::server(config, server_addr())?;
1819

1920
// Start iterating over incoming connections.
2021
while let Some(conn) = endpoint.accept().await {
21-
let mut connection = conn.await?;
22+
let connection = conn.await?;
2223

2324
// Save connection somewhere, start transferring, receiving data, see DataTransfer tutorial.
2425
}
2526

2627
Ok(())
2728
}
2829

30+
#[allow(dead_code, unused_variables)] // Included in `set-up-connection.md`
2931
async fn client() -> Result<(), Box<dyn Error>> {
3032
// Bind this endpoint to a UDP socket on the given client address.
31-
let mut endpoint = Endpoint::client(client_addr())?;
33+
let endpoint = Endpoint::client(client_addr())?;
3234

3335
// Connect to the server passing in the server name which is supposed to be in the server certificate.
3436
let connection = endpoint.connect(server_addr(), SERVER_NAME)?.await?;
@@ -37,3 +39,5 @@ async fn client() -> Result<(), Box<dyn Error>> {
3739

3840
Ok(())
3941
}
42+
43+
fn main() {}

0 commit comments

Comments
 (0)