Skip to content

Commit 15b88d7

Browse files
msrd0Empty2k12
andauthored
Remove non-utc trait impls and make InfluxDbWriteable fail-able (#174)
* Remove non-utc trait impls; start adjusting the derive macro * finish adjusting the derive macro * reformat code in doc comments using nightly rustfmt * fix doc tests * update readme * fix accidentially bumping MSRV I didn't know core::error::Error would be a problem ... TIL * Bump MSRV to 1.70 Better than the MSRV of 1.81 for core::error But I'd really like to use write! in proc-macros ... --------- Co-authored-by: Gero Gerke <hello@gero.dev>
1 parent c4c8528 commit 15b88d7

File tree

14 files changed

+369
-156
lines changed

14 files changed

+369
-156
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resolver = "2"
77
[workspace.package]
88
authors = ["Gero Gerke <git@gero.dev>", "Dominic <git@msrd0.de>"]
99
edition = "2021"
10-
rust-version = "1.67.1"
10+
rust-version = "1.70"
1111
license = "MIT"
1212
repository = "https://github.com/influxdb-rs/influxdb-rust"
1313

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<a href="https://www.rust-lang.org/en-US/">
2626
<img src="https://img.shields.io/badge/Made%20with-Rust-orange.svg" alt='Build with Rust' />
2727
</a>
28-
<a href="https://github.com/rust-lang/rust/releases/tag/1.67.1">
29-
<img src="https://img.shields.io/badge/rustc-1.67.1+-yellow.svg" alt='Minimum Rust Version: 1.67.1' />
28+
<a href="https://github.com/rust-lang/rust/releases/tag/1.70.0">
29+
<img src="https://img.shields.io/badge/rustc-1.70.0+-yellow.svg" alt='Minimum Rust Version: 1.70.0' />
3030
</a>
3131
</p>
3232

@@ -75,17 +75,19 @@ async fn main() -> Result<(), Error> {
7575
// Let's write some data into a measurement called `weather`
7676
let weather_readings = vec![
7777
WeatherReading {
78-
time: Timestamp::Hours(1).into(),
78+
time: Timestamp::Hours(1).try_into().unwrap(),
7979
humidity: 30,
8080
wind_direction: String::from("north"),
8181
}
82-
.into_query("weather"),
82+
.try_into_query("weather")
83+
.unwrap(),
8384
WeatherReading {
84-
time: Timestamp::Hours(2).into(),
85+
time: Timestamp::Hours(2).try_into().unwrap(),
8586
humidity: 40,
8687
wind_direction: String::from("west"),
8788
}
88-
.into_query("weather"),
89+
.try_into_query("weather")
90+
.unwrap(),
8991
];
9092

9193
client.query(weather_readings).await?;
@@ -129,7 +131,7 @@ To communicate with InfluxDB, you can choose the HTTP backend to be used configu
129131
@ 2020-2024 Gero Gerke, msrd0 and [contributors].
130132

131133
[contributors]: https://github.com/influxdb-rs/influxdb-rust/graphs/contributors
132-
[__cargo_doc2readme_dependencies_info]: ggGkYW0CYXSEGzJ_QpW55zB1G0S-TER-rIfLG2gXv8EYBG3jG1nuXXn-kdx-YXKEG8LHWNBBuXgSGz-2Lrx4E_kTG0bJiXb6A8zNG9GhXhvU8L0xYWSBgmhpbmZsdXhkYmUwLjcuMg
134+
[__cargo_doc2readme_dependencies_info]: ggGkYW0CYXSEGzJ_QpW55zB1G0S-TER-rIfLG2gXv8EYBG3jG1nuXXn-kdx-YXKEG5esg8JWCUnDGygXCh47ngu0G4kPgAyV809_G2pbKPyN9jeVYWSBgmhpbmZsdXhkYmUwLjcuMg
133135
[__link0]: https://github.com/influxdb-rs/influxdb-rust/blob/main/CONTRIBUTING.md
134136
[__link1]: https://github.com/influxdb-rs/influxdb-rust/blob/main/CODE_OF_CONDUCT.md
135137
[__link2]: https://github.com/influxdb-rs/influxdb-rust/blob/main/CHANGELOG.md

benches/client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use chrono::{DateTime, Utc};
2-
use influxdb::Error;
3-
use influxdb::InfluxDbWriteable;
4-
use influxdb::{Client, ReadQuery};
2+
use influxdb::{Client, Error, InfluxDbWriteable, ReadQuery};
53
use std::sync::Arc;
64
use std::time::Instant;
75
use tokio::sync::mpsc::unbounded_channel;

influxdb/src/client/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use std::fmt::{self, Debug, Formatter};
2222
use std::sync::Arc;
2323

2424
use crate::query::QueryType;
25-
use crate::Error;
26-
use crate::Query;
25+
use crate::{Error, Query};
2726

2827
#[derive(Clone)]
2928
/// Internal Representation of a Client
@@ -188,21 +187,21 @@ impl Client {
188187
/// # Examples
189188
///
190189
/// ```rust,no_run
191-
/// use influxdb::{Client, Query, Timestamp};
192-
/// use influxdb::InfluxDbWriteable;
190+
/// use influxdb::{Client, InfluxDbWriteable, Query, Timestamp};
193191
/// use std::time::{SystemTime, UNIX_EPOCH};
194192
///
195193
/// # #[tokio::main]
196194
/// # async fn main() -> Result<(), influxdb::Error> {
197195
/// let start = SystemTime::now();
198196
/// let since_the_epoch = start
199-
/// .duration_since(UNIX_EPOCH)
200-
/// .expect("Time went backwards")
201-
/// .as_millis();
197+
/// .duration_since(UNIX_EPOCH)
198+
/// .expect("Time went backwards")
199+
/// .as_millis();
202200
///
203201
/// let client = Client::new("http://localhost:8086", "test");
204202
/// let query = Timestamp::Milliseconds(since_the_epoch)
205-
/// .into_query("weather")
203+
/// .try_into_query("weather")
204+
/// .unwrap()
206205
/// .add_field("temperature", 82);
207206
/// let results = client.query(query).await?;
208207
///

influxdb/src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@ pub enum Error {
3333
/// Error happens when HTTP request fails
3434
ConnectionError { error: String },
3535
}
36+
37+
#[cfg(feature = "chrono")]
38+
#[derive(Clone, Copy, Debug, Error)]
39+
#[error("The timestamp is too large to fit into an i64.")]
40+
pub struct TimestampTooLargeError(pub(crate) ());
41+
42+
#[cfg(any(feature = "chrono", feature = "time"))]
43+
#[derive(Clone, Copy, Debug, Error)]
44+
pub enum TimeTryFromError<T, I> {
45+
TimeError(#[source] T),
46+
IntError(#[source] I),
47+
}

influxdb/src/integrations/serde_integration/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
//! .series
3434
//! .into_iter()
3535
//! .map(|mut city_series| {
36-
//! let city_name =
37-
//! city_series.name.split("_").collect::<Vec<&str>>().remove(2);
36+
//! let city_name = city_series.name.split("_").collect::<Vec<&str>>().remove(2);
3837
//! Weather {
3938
//! weather: city_series.values.remove(0),
4039
//! city_name: city_name.to_string(),
@@ -50,7 +49,8 @@ mod de;
5049
use serde::de::DeserializeOwned;
5150
use serde_derive::Deserialize;
5251

53-
use crate::{client::check_status, Client, Error, Query, ReadQuery};
52+
use crate::client::check_status;
53+
use crate::{Client, Error, Query, ReadQuery};
5454

5555
#[derive(Deserialize)]
5656
#[doc(hidden)]

influxdb/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//! # Quickstart
1717
//!
1818
//! Add the following to your `Cargo.toml`
19-
//!
2019
#![doc = cargo_toml!(indent="", "derive")]
2120
//!
2221
//! For an example with using Serde deserialization, please refer to [serde_integration](crate::integrations::serde_integration)
@@ -41,17 +40,19 @@
4140
//! // Let's write some data into a measurement called `weather`
4241
//! let weather_readings = vec![
4342
//! WeatherReading {
44-
//! time: Timestamp::Hours(1).into(),
43+
//! time: Timestamp::Hours(1).try_into().unwrap(),
4544
//! humidity: 30,
4645
//! wind_direction: String::from("north"),
4746
//! }
48-
//! .into_query("weather"),
47+
//! .try_into_query("weather")
48+
//! .unwrap(),
4949
//! WeatherReading {
50-
//! time: Timestamp::Hours(2).into(),
50+
//! time: Timestamp::Hours(2).try_into().unwrap(),
5151
//! humidity: 40,
5252
//! wind_direction: String::from("west"),
5353
//! }
54-
//! .into_query("weather"),
54+
//! .try_into_query("weather")
55+
//! .unwrap(),
5556
//! ];
5657
//!
5758
//! client.query(weather_readings).await?;
@@ -123,11 +124,9 @@ mod query;
123124

124125
pub use client::Client;
125126
pub use error::Error;
126-
pub use query::{
127-
read_query::ReadQuery,
128-
write_query::{Type, WriteQuery},
129-
InfluxDbWriteable, Query, QueryType, Timestamp, ValidQuery,
130-
};
127+
pub use query::read_query::ReadQuery;
128+
pub use query::write_query::{Type, WriteQuery};
129+
pub use query::{InfluxDbWriteable, Query, QueryType, Timestamp, ValidQuery};
131130

132131
#[cfg(feature = "serde")]
133132
pub mod integrations {

0 commit comments

Comments
 (0)