Skip to content

Commit a7a56df

Browse files
authored
README: display clear errors in the example (#130)
1 parent e9845a1 commit a7a56df

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -62,48 +62,47 @@ For an example with using Serde deserialization, please refer to [serde_integrat
6262

6363

6464
```rust
65-
use influxdb::{Client, Query, Timestamp, ReadQuery};
66-
use influxdb::InfluxDbWriteable;
6765
use chrono::{DateTime, Utc};
66+
use influxdb::{Client, Error, InfluxDbWriteable, ReadQuery, Timestamp};
6867

6968
#[tokio::main]
7069
// or #[async_std::main] if you prefer
71-
async fn main() {
70+
async fn main() -> Result<(), Error> {
7271
// Connect to db `test` on `http://localhost:8086`
7372
let client = Client::new("http://localhost:8086", "test");
7473

7574
#[derive(InfluxDbWriteable)]
7675
struct WeatherReading {
7776
time: DateTime<Utc>,
7877
humidity: i32,
79-
#[influxdb(tag)] wind_direction: String,
78+
#[influxdb(tag)]
79+
wind_direction: String,
8080
}
8181

8282
// Let's write some data into a measurement called `weather`
83-
let weather_readings = vec!(
83+
let weather_readings = vec![
8484
WeatherReading {
8585
time: Timestamp::Hours(1).into(),
8686
humidity: 30,
8787
wind_direction: String::from("north"),
88-
}.into_query("weather"),
88+
}
89+
.into_query("weather"),
8990
WeatherReading {
9091
time: Timestamp::Hours(2).into(),
9192
humidity: 40,
9293
wind_direction: String::from("west"),
93-
}.into_query("weather"),
94-
);
94+
}
95+
.into_query("weather"),
96+
];
9597

96-
let write_result = client
97-
.query(weather_readings)
98-
.await;
99-
assert!(write_result.is_ok(), "Write result was not okay");
98+
client.query(weather_readings).await?;
10099

101100
// Let's see if the data we wrote is there
102101
let read_query = ReadQuery::new("SELECT * FROM weather");
103102

104-
let read_result = client.query(read_query).await;
105-
assert!(read_result.is_ok(), "Read result was not ok");
106-
println!("{}", read_result.unwrap());
103+
let read_result = client.query(read_query).await?;
104+
println!("{}", read_result);
105+
Ok(())
107106
}
108107
```
109108

@@ -167,7 +166,7 @@ To communicate with InfluxDB, you can choose the HTTP backend to be used configu
167166
@ 2020 Gero Gerke and [contributors].
168167

169168
[contributors]: https://github.com/influxdb-rs/influxdb-rust/graphs/contributors
170-
[__cargo_doc2readme_dependencies_info]: ggGkYW0BYXSEG64av5CnNoNoGw8lPMr2b0MoG44uU0T70vGSG7osgcbjN7SoYXKEG8qCijK3OhAgG9r5dMb74ZyFGy-UgqMKZw5_G6wZmUfHdMJDYWSBgmhpbmZsdXhkYmUwLjcuMQ
169+
[__cargo_doc2readme_dependencies_info]: ggGkYW0BYXSEG64av5CnNoNoGw8lPMr2b0MoG44uU0T70vGSG7osgcbjN7SoYXKEGzTIyZ81-O7yGzBPOAorSf5GGwJWIVB6K85jG41Hl-f5lXJVYWSBgmhpbmZsdXhkYmUwLjcuMQ
171170
[__link0]: https://github.com/influxdb-rs/influxdb-rust/blob/main/CONTRIBUTING.md
172171
[__link1]: https://github.com/influxdb-rs/influxdb-rust/blob/main/CODE_OF_CONDUCT.md
173172
[__link10]: https://curl.se/libcurl/

influxdb/src/lib.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,47 @@
2525
//! For an example with using Serde deserialization, please refer to [serde_integration](crate::integrations::serde_integration)
2626
//!
2727
//! ```rust,no_run
28-
//! use influxdb::{Client, Query, Timestamp, ReadQuery};
29-
//! use influxdb::InfluxDbWriteable;
3028
//! use chrono::{DateTime, Utc};
29+
//! use influxdb::{Client, Error, InfluxDbWriteable, ReadQuery, Timestamp};
3130
//!
3231
//! #[tokio::main]
3332
//! // or #[async_std::main] if you prefer
34-
//! async fn main() {
33+
//! async fn main() -> Result<(), Error> {
3534
//! // Connect to db `test` on `http://localhost:8086`
3635
//! let client = Client::new("http://localhost:8086", "test");
3736
//!
3837
//! #[derive(InfluxDbWriteable)]
3938
//! struct WeatherReading {
4039
//! time: DateTime<Utc>,
4140
//! humidity: i32,
42-
//! #[influxdb(tag)] wind_direction: String,
41+
//! #[influxdb(tag)]
42+
//! wind_direction: String,
4343
//! }
4444
//!
4545
//! // Let's write some data into a measurement called `weather`
46-
//! let weather_readings = vec!(
46+
//! let weather_readings = vec![
4747
//! WeatherReading {
4848
//! time: Timestamp::Hours(1).into(),
4949
//! humidity: 30,
5050
//! wind_direction: String::from("north"),
51-
//! }.into_query("weather"),
51+
//! }
52+
//! .into_query("weather"),
5253
//! WeatherReading {
5354
//! time: Timestamp::Hours(2).into(),
5455
//! humidity: 40,
5556
//! wind_direction: String::from("west"),
56-
//! }.into_query("weather"),
57-
//! );
57+
//! }
58+
//! .into_query("weather"),
59+
//! ];
5860
//!
59-
//! let write_result = client
60-
//! .query(weather_readings)
61-
//! .await;
62-
//! assert!(write_result.is_ok(), "Write result was not okay");
61+
//! client.query(weather_readings).await?;
6362
//!
6463
//! // Let's see if the data we wrote is there
6564
//! let read_query = ReadQuery::new("SELECT * FROM weather");
6665
//!
67-
//! let read_result = client.query(read_query).await;
68-
//! assert!(read_result.is_ok(), "Read result was not ok");
69-
//! println!("{}", read_result.unwrap());
66+
//! let read_result = client.query(read_query).await?;
67+
//! println!("{}", read_result);
68+
//! Ok(())
7069
//! }
7170
//! ```
7271
//!

0 commit comments

Comments
 (0)