Skip to content

Commit 14165e1

Browse files
authored
fix: fixed compilation warnings & deprecations (#479)
* fix: fixed compilation warnings & deprecations * fix: removed premature close()
1 parent 124192b commit 14165e1

File tree

8 files changed

+25
-47
lines changed

8 files changed

+25
-47
lines changed

aw-client-rust/src/blocking.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::future::Future;
2-
use std::vec::Vec;
32
use std::{collections::HashMap, error::Error};
43

54
use chrono::{DateTime, Utc};

aw-client-rust/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extern crate tokio;
77

88
pub mod blocking;
99

10-
use std::vec::Vec;
1110
use std::{collections::HashMap, error::Error};
1211

1312
use chrono::{DateTime, Utc};

aw-datastore/src/datastore.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use std::collections::HashMap;
22

33
use chrono::DateTime;
44
use chrono::Duration;
5-
use chrono::NaiveDateTime;
6-
use chrono::TimeZone;
75
use chrono::Utc;
86

97
use rusqlite::Connection;
@@ -233,10 +231,7 @@ impl DatastoreInstance {
233231
Some(starttime_ns) => {
234232
let seconds: i64 = starttime_ns / 1_000_000_000;
235233
let subnanos: u32 = (starttime_ns % 1_000_000_000) as u32;
236-
Some(TimeZone::from_utc_datetime(
237-
&Utc,
238-
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
239-
))
234+
Some(DateTime::from_timestamp(seconds, subnanos).unwrap())
240235
}
241236
None => None,
242237
};
@@ -246,10 +241,7 @@ impl DatastoreInstance {
246241
Some(endtime_ns) => {
247242
let seconds: i64 = endtime_ns / 1_000_000_000;
248243
let subnanos: u32 = (endtime_ns % 1_000_000_000) as u32;
249-
Some(TimeZone::from_utc_datetime(
250-
&Utc,
251-
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
252-
))
244+
Some(DateTime::from_timestamp(seconds, subnanos).unwrap())
253245
}
254246
None => None,
255247
};
@@ -689,10 +681,7 @@ impl DatastoreInstance {
689681

690682
Ok(Event {
691683
id: Some(id),
692-
timestamp: TimeZone::from_utc_datetime(
693-
&Utc,
694-
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
695-
),
684+
timestamp: DateTime::from_timestamp(time_seconds, time_subnanos).unwrap(),
696685
duration: Duration::nanoseconds(duration_ns),
697686
data,
698687
})
@@ -784,10 +773,7 @@ impl DatastoreInstance {
784773

785774
Ok(Event {
786775
id: Some(id),
787-
timestamp: TimeZone::from_utc_datetime(
788-
&Utc,
789-
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
790-
),
776+
timestamp: DateTime::from_timestamp(time_seconds, time_subnanos).unwrap(),
791777
duration: Duration::nanoseconds(duration_ns),
792778
data,
793779
})

aw-query/src/datatype.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::convert::{TryFrom, TryInto};
32
use std::fmt;
43

54
use super::functions;

aw-query/src/functions.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ pub fn fill_env(env: &mut VarEnv) {
116116
}
117117

118118
mod qfunctions {
119-
use std::convert::TryFrom;
120-
use std::convert::TryInto;
121-
122119
use aw_datastore::Datastore;
123120
use aw_models::Event;
124121
use aw_transform::classify::Rule;

aw-server/src/endpoints/bucket.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn buckets_get(
3030

3131
#[get("/<bucket_id>")]
3232
pub fn bucket_get(
33-
bucket_id: String,
33+
bucket_id: &str,
3434
state: &State<ServerState>,
3535
) -> Result<Json<Bucket>, HttpErrorJson> {
3636
let datastore = endpoints_get_lock!(state.datastore);
@@ -46,13 +46,13 @@ pub fn bucket_get(
4646
/// This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
4747
#[post("/<bucket_id>", data = "<message>", format = "application/json")]
4848
pub fn bucket_new(
49-
bucket_id: String,
49+
bucket_id: &str,
5050
message: Json<Bucket>,
5151
state: &State<ServerState>,
5252
) -> Result<(), HttpErrorJson> {
5353
let mut bucket = message.into_inner();
5454
if bucket.id != bucket_id {
55-
bucket.id = bucket_id;
55+
bucket.id = bucket_id.to_string();
5656
}
5757
if bucket.hostname == "!local" {
5858
bucket.hostname = gethostname()
@@ -72,7 +72,7 @@ pub fn bucket_new(
7272

7373
#[get("/<bucket_id>/events?<start>&<end>&<limit>")]
7474
pub fn bucket_events_get(
75-
bucket_id: String,
75+
bucket_id: &str,
7676
start: Option<String>,
7777
end: Option<String>,
7878
limit: Option<u64>,
@@ -104,7 +104,7 @@ pub fn bucket_events_get(
104104
None => None,
105105
};
106106
let datastore = endpoints_get_lock!(state.datastore);
107-
let res = datastore.get_events(&bucket_id, starttime, endtime, limit);
107+
let res = datastore.get_events(bucket_id, starttime, endtime, limit);
108108
match res {
109109
Ok(events) => Ok(Json(events)),
110110
Err(err) => Err(err.into()),
@@ -115,13 +115,13 @@ pub fn bucket_events_get(
115115
// See: https://api.rocket.rs/master/rocket/struct.Route.html#resolving-collisions
116116
#[get("/<bucket_id>/events/<event_id>?<_unused..>")]
117117
pub fn bucket_events_get_single(
118-
bucket_id: String,
118+
bucket_id: &str,
119119
event_id: i64,
120120
_unused: Option<u64>,
121121
state: &State<ServerState>,
122122
) -> Result<Json<Event>, HttpErrorJson> {
123123
let datastore = endpoints_get_lock!(state.datastore);
124-
let res = datastore.get_event(&bucket_id, event_id);
124+
let res = datastore.get_event(bucket_id, event_id);
125125
match res {
126126
Ok(events) => Ok(Json(events)),
127127
Err(err) => Err(err.into()),
@@ -130,12 +130,12 @@ pub fn bucket_events_get_single(
130130

131131
#[post("/<bucket_id>/events", data = "<events>", format = "application/json")]
132132
pub fn bucket_events_create(
133-
bucket_id: String,
133+
bucket_id: &str,
134134
events: Json<Vec<Event>>,
135135
state: &State<ServerState>,
136136
) -> Result<Json<Vec<Event>>, HttpErrorJson> {
137137
let datastore = endpoints_get_lock!(state.datastore);
138-
let res = datastore.insert_events(&bucket_id, &events);
138+
let res = datastore.insert_events(bucket_id, &events);
139139
match res {
140140
Ok(events) => Ok(Json(events)),
141141
Err(err) => Err(err.into()),
@@ -148,26 +148,26 @@ pub fn bucket_events_create(
148148
format = "application/json"
149149
)]
150150
pub fn bucket_events_heartbeat(
151-
bucket_id: String,
151+
bucket_id: &str,
152152
heartbeat_json: Json<Event>,
153153
pulsetime: f64,
154154
state: &State<ServerState>,
155155
) -> Result<Json<Event>, HttpErrorJson> {
156156
let heartbeat = heartbeat_json.into_inner();
157157
let datastore = endpoints_get_lock!(state.datastore);
158-
match datastore.heartbeat(&bucket_id, heartbeat, pulsetime) {
158+
match datastore.heartbeat(bucket_id, heartbeat, pulsetime) {
159159
Ok(e) => Ok(Json(e)),
160160
Err(err) => Err(err.into()),
161161
}
162162
}
163163

164164
#[get("/<bucket_id>/events/count")]
165165
pub fn bucket_event_count(
166-
bucket_id: String,
166+
bucket_id: &str,
167167
state: &State<ServerState>,
168168
) -> Result<Json<u64>, HttpErrorJson> {
169169
let datastore = endpoints_get_lock!(state.datastore);
170-
let res = datastore.get_event_count(&bucket_id, None, None);
170+
let res = datastore.get_event_count(bucket_id, None, None);
171171
match res {
172172
Ok(eventcount) => Ok(Json(eventcount as u64)),
173173
Err(err) => Err(err.into()),
@@ -176,44 +176,44 @@ pub fn bucket_event_count(
176176

177177
#[delete("/<bucket_id>/events/<event_id>")]
178178
pub fn bucket_events_delete_by_id(
179-
bucket_id: String,
179+
bucket_id: &str,
180180
event_id: i64,
181181
state: &State<ServerState>,
182182
) -> Result<(), HttpErrorJson> {
183183
let datastore = endpoints_get_lock!(state.datastore);
184-
match datastore.delete_events_by_id(&bucket_id, vec![event_id]) {
184+
match datastore.delete_events_by_id(bucket_id, vec![event_id]) {
185185
Ok(_) => Ok(()),
186186
Err(err) => Err(err.into()),
187187
}
188188
}
189189

190190
#[get("/<bucket_id>/export")]
191191
pub fn bucket_export(
192-
bucket_id: String,
192+
bucket_id: &str,
193193
state: &State<ServerState>,
194194
) -> Result<BucketsExportRocket, HttpErrorJson> {
195195
let datastore = endpoints_get_lock!(state.datastore);
196196
let mut export = BucketsExport {
197197
buckets: HashMap::new(),
198198
};
199-
let mut bucket = match datastore.get_bucket(&bucket_id) {
199+
let mut bucket = match datastore.get_bucket(bucket_id) {
200200
Ok(bucket) => bucket,
201201
Err(err) => return Err(err.into()),
202202
};
203203
/* TODO: Replace expect with http error */
204204
let events = datastore
205-
.get_events(&bucket_id, None, None, None)
205+
.get_events(bucket_id, None, None, None)
206206
.expect("Failed to get events for bucket");
207207
bucket.events = Some(TryVec::new(events));
208-
export.buckets.insert(bucket_id, bucket);
208+
export.buckets.insert(bucket_id.into(), bucket);
209209

210210
Ok(export.into())
211211
}
212212

213213
#[delete("/<bucket_id>")]
214-
pub fn bucket_delete(bucket_id: String, state: &State<ServerState>) -> Result<(), HttpErrorJson> {
214+
pub fn bucket_delete(bucket_id: &str, state: &State<ServerState>) -> Result<(), HttpErrorJson> {
215215
let datastore = endpoints_get_lock!(state.datastore);
216-
match datastore.delete_bucket(&bucket_id) {
216+
match datastore.delete_bucket(bucket_id) {
217217
Ok(_) => Ok(()),
218218
Err(err) => Err(err.into()),
219219
}

aw-sync/src/sync_wrapper.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::boxed::Box;
21
use std::error::Error;
32
use std::fs;
43
use std::net::TcpStream;

aw-sync/src/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::boxed::Box;
21
use std::error::Error;
32
use std::ffi::OsStr;
43
use std::fs;

0 commit comments

Comments
 (0)