Skip to content

Commit c719181

Browse files
Devdutt Shenoiswanandx
andauthored
refactor(rumqttc): clean-up examples (#794)
Co-authored-by: swanandx <[email protected]>
1 parent e63925a commit c719181

16 files changed

+44
-61
lines changed

Cargo.lock

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

rumqttc/Cargo.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,24 @@ color-backtrace = "0.6"
5454
matches = "0.1"
5555
pretty_assertions = "1"
5656
pretty_env_logger = "0.5"
57-
rustls = "0.21"
58-
rustls-native-certs = "0.6"
5957
serde = { version = "1", features = ["derive"] }
60-
tokio = { version = "1", features = ["full", "macros"] }
58+
59+
[[example]]
60+
name = "tls"
61+
path = "examples/tls.rs"
62+
required-features = ["use-rustls"]
63+
64+
[[example]]
65+
name = "tls2"
66+
path = "examples/tls2.rs"
67+
required-features = ["use-rustls"]
68+
69+
[[example]]
70+
name = "websocket"
71+
path = "examples/websocket.rs"
72+
required-features = ["websocket"]
73+
74+
[[example]]
75+
name = "websocket_proxy"
76+
path = "examples/websocket_proxy.rs"
77+
required-features = ["websocket", "proxy"]

rumqttc/examples/async_manual_acks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tokio::{task, time};
22

3-
use rumqttc::{self, AsyncClient, Event, EventLoop, Incoming, MqttOptions, QoS};
3+
use rumqttc::{AsyncClient, Event, EventLoop, Incoming, MqttOptions, QoS};
44
use std::error::Error;
55
use std::time::Duration;
66

@@ -14,7 +14,7 @@ fn create_conn() -> (AsyncClient, EventLoop) {
1414
AsyncClient::new(mqttoptions, 10)
1515
}
1616

17-
#[tokio::main(worker_threads = 1)]
17+
#[tokio::main(flavor = "current_thread")]
1818
async fn main() -> Result<(), Box<dyn Error>> {
1919
pretty_env_logger::init();
2020

rumqttc/examples/async_manual_acks_v5.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(dead_code, unused_imports)]
21
use rumqttc::v5::mqttbytes::v5::Packet;
32
use rumqttc::v5::mqttbytes::QoS;
43
use tokio::{task, time};
@@ -17,7 +16,7 @@ fn create_conn() -> (AsyncClient, EventLoop) {
1716
AsyncClient::new(mqttoptions, 10)
1817
}
1918

20-
#[tokio::main(worker_threads = 1)]
19+
#[tokio::main(flavor = "current_thread")]
2120
async fn main() -> Result<(), Box<dyn Error>> {
2221
// todo!("fix this example with new way of spawning clients")
2322
pretty_env_logger::init();

rumqttc/examples/asyncpubsub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use tokio::{task, time};
22

3-
use rumqttc::{self, AsyncClient, MqttOptions, QoS};
3+
use rumqttc::{AsyncClient, MqttOptions, QoS};
44
use std::error::Error;
55
use std::time::Duration;
66

7-
#[tokio::main(worker_threads = 1)]
7+
#[tokio::main(flavor = "current_thread")]
88
async fn main() -> Result<(), Box<dyn Error>> {
99
pretty_env_logger::init();
1010
// color_backtrace::install();

rumqttc/examples/asyncpubsub_v5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rumqttc::v5::{AsyncClient, MqttOptions};
55
use std::error::Error;
66
use std::time::Duration;
77

8-
#[tokio::main(worker_threads = 1)]
8+
#[tokio::main(flavor = "current_thread")]
99
async fn main() -> Result<(), Box<dyn Error>> {
1010
pretty_env_logger::init();
1111
// color_backtrace::install();

rumqttc/examples/serde.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fn main() {
5151
});
5252

5353
// Iterate to poll the eventloop for connection progress
54-
for notification in connection.iter() {
55-
if let Ok(Event::Incoming(Incoming::Publish(packet))) = notification {
54+
for notification in connection.iter().flatten() {
55+
if let Event::Incoming(Incoming::Publish(packet)) = notification {
5656
match Message::try_from(packet.payload.as_ref()) {
5757
Ok(message) => println!("Payload = {message:?}"),
5858
Err(error) => println!("Error = {error}"),

rumqttc/examples/subscription_ids.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rumqttc::v5::{AsyncClient, MqttOptions};
66
use std::error::Error;
77
use std::time::Duration;
88

9-
#[tokio::main(worker_threads = 1)]
9+
#[tokio::main(flavor = "current_thread")]
1010
async fn main() -> Result<(), Box<dyn Error>> {
1111
pretty_env_logger::init();
1212

rumqttc/examples/syncpubsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rumqttc::{self, Client, LastWill, MqttOptions, QoS};
1+
use rumqttc::{Client, LastWill, MqttOptions, QoS};
22
use std::thread;
33
use std::time::Duration;
44

rumqttc/examples/syncrecv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rumqttc::{self, Client, LastWill, MqttOptions, QoS};
1+
use rumqttc::{Client, LastWill, MqttOptions, QoS};
22
use std::thread;
33
use std::time::Duration;
44

0 commit comments

Comments
 (0)