Skip to content

Commit baa1751

Browse files
committed
refactor(cfg): improve conditional compilation
Add the required features for each example. Signed-off-by: Joshua Chapman <joshua.chapman@secomind.com>
1 parent 7050016 commit baa1751

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,13 @@ webpki-roots = "0.26.0"
164164
# Transitive dependencies
165165
litemap = "=0.7.4"
166166
zerofrom = "=0.1.5"
167+
168+
[[example]]
169+
name = "msghub_client"
170+
path = "examples/message_hub_client/main.rs"
171+
required-features = ["message-hub", "derive"]
172+
173+
[[example]]
174+
name = "object_datastream"
175+
path = "examples/object_datastream/main.rs"
176+
required-features = ["derive"]

docs/connect-to-the-astarte-message-hub.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The Astarte Device SDK supports two different connection types:
1515
Here we will go through, step by step, on how to connect and send data to the Message Hub.
1616

1717
> You can find the full code by going to the
18-
> [msghub-client example](https://github.com/astarte-platform/astarte-device-sdk-rust/tree/master/examples/msghub-client)
18+
> [message hub client example](https://github.com/astarte-platform/astarte-device-sdk-rust/tree/master/examples/message_hub_client)
1919
2020
## Before you begin
2121

@@ -37,9 +37,9 @@ Hub server, and all the keys necessary to register the Message Hub server as a n
3737
### Message Hub Server
3838

3939
To register the server you can follow the guide and examples in
40-
[the MessageHub repository](https://github.com/astarte-platform/astarte-message-hub). Following
41-
this, we assume the Server is listening on the same machine IP v4 address `127.0.0.1` and port
42-
`50051`.
40+
[the Astarte MessageHub repository](https://github.com/astarte-platform/astarte-message-hub).
41+
Following this, we assume the Server is listening on the same machine IP v4 address `127.0.0.1` and
42+
port `50051`.
4343

4444
#### Client Auth
4545

@@ -286,8 +286,8 @@ function that we declared previously.
286286
# const NODE_UUID: uuid::Uuid = uuid::uuid!("0444d8c3-f3f1-4b89-9e68-6ffb50ec1839");
287287
# const MESSAGE_HUB_URL: &str = "http://127.0.0.1:50051";
288288
# const STORE_DIRECTORY: &str = "./store-dir";
289-
290-
// NOTO: set the interface directory in your project, these are relative to this file
289+
#
290+
// NOTE: set the interface directory in your project, these are relative to this file
291291
const AGGREGATED_DEVICE: &str = include_str!("../../docs/interfaces/org.astarte-platform.rust.get-started.Aggregated.json");
292292
const INDIVIDUAL_DEVICE: &str = include_str!("../../docs/interfaces/org.astarte-platform.rust.get-started.IndividualDevice.json");
293293
const INDIVIDUAL_SERVER: &str = include_str!("../../docs/interfaces/org.astarte-platform.rust.get-started.IndividualServer.json");
@@ -334,8 +334,6 @@ We can now spawn a task to receive data from Astarte. Using the
334334
# transport::grpc::{tonic::transport::Endpoint, Grpc, GrpcConfig},
335335
# DeviceClient, DeviceConnection,
336336
# };
337-
338-
339337
# #[cfg(not(feature = "derive"))]
340338
# use astarte_device_sdk_derive::FromEvent;
341339
# #[cfg(feature = "derive")]
@@ -395,8 +393,6 @@ async fn receive_data(client: DeviceClient<SqliteStore>) -> eyre::Result<()> {
395393
}
396394
}
397395
398-
399-
400396
#[tokio::main]
401397
async fn main() -> eyre::Result<()> {
402398
# let mut tasks = tokio::task::JoinSet::new();
@@ -446,7 +442,7 @@ convert the Rust struct in an Object Aggregate to send.
446442
# transport::grpc::{tonic::transport::Endpoint, Grpc, GrpcConfig},
447443
# DeviceClient, DeviceConnection,
448444
# };
449-
445+
#
450446
use std::time::Duration;
451447
452448
# #[cfg(feature = "derive")]
File renamed without changes.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
//! Example on connecting to the Astarte MessageHub.
2020
21-
// Features required by the example
22-
#![cfg(all(feature = "message-hub", feature = "derive"))]
23-
2421
use std::{f64, time::Duration};
2522

2623
use astarte_device_sdk::{

examples/object_datastream/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ use std::time::Duration;
2222

2323
use serde::{Deserialize, Serialize};
2424

25-
#[cfg(feature = "derive")]
2625
use astarte_device_sdk::AstarteAggregate;
2726
use astarte_device_sdk::{
2827
builder::DeviceBuilder, prelude::*, store::memory::MemoryStore, transport::mqtt::MqttConfig,
2928
};
30-
#[cfg(not(feature = "derive"))]
31-
use astarte_device_sdk_derive::AstarteAggregate;
3229
use tokio::task::JoinSet;
3330
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
3431

src/store/sqlite/statements.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ impl ReadConnection {
197197
pub(crate) fn connect(db_file: impl AsRef<Path>) -> Result<Self, SqliteError> {
198198
let flags = OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_NO_MUTEX;
199199

200-
let mut connection =
200+
let connection =
201201
Connection::open_with_flags(db_file, flags).map_err(SqliteError::Connection)?;
202202

203+
#[cfg(feature = "sqlite-trace")]
204+
let mut connection = connection;
203205
#[cfg(feature = "sqlite-trace")]
204206
connection.trace(Some(trace_sqlite));
205207

0 commit comments

Comments
 (0)