Skip to content

Commit 4ceb9c2

Browse files
aw-server: Clippy fixes
1 parent 718ebfd commit 4ceb9c2

File tree

12 files changed

+71
-83
lines changed

12 files changed

+71
-83
lines changed

aw-server/src/config.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ impl Default for AWConfig {
4040

4141
impl AWConfig {
4242
pub fn to_rocket_config(&self) -> rocket::Config {
43-
let env = match self.testing {
44-
true => Environment::Production,
45-
false => Environment::Development,
43+
let env = if self.testing {
44+
Environment::Production
45+
} else {
46+
Environment::Development
4647
};
4748
// Needed for bucket imports
48-
let limits = Limits::new().limit("json", 1 * 1000 * 1000 * 1000);
49+
let limits = Limits::new().limit("json", 1_000_000_000);
4950

5051
Config::build(env)
5152
.address(self.address.clone())
@@ -70,9 +71,10 @@ fn default_testing() -> bool {
7071
}
7172

7273
fn default_port() -> u16 {
73-
match is_testing() {
74-
false => 5600,
75-
true => 5666,
74+
if is_testing() {
75+
5666
76+
} else {
77+
5600
7678
}
7779
}
7880

aw-server/src/dirs.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use std::path::PathBuf;
33
#[cfg(not(target_os = "android"))]
44
use std::fs;
55

6-
#[cfg(not(target_os = "android"))]
7-
use appdirs;
8-
96
#[cfg(target_os = "android")]
107
use std::sync::Mutex;
118

aw-server/src/endpoints/bucket.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ pub fn buckets_get(state: State<ServerState>) -> Result<Json<HashMap<String, Buc
2525
let datastore = endpoints_get_lock!(state.datastore);
2626
match datastore.get_buckets() {
2727
Ok(bucketlist) => Ok(Json(bucketlist)),
28-
Err(e) => match e {
29-
_ => {
30-
warn!("Unexpected error: {:?}", e);
31-
Err(Status::InternalServerError)
32-
}
33-
},
28+
Err(e) => {
29+
warn!("Unexpected error: {:?}", e);
30+
Err(Status::InternalServerError)
31+
}
3432
}
3533
}
3634

@@ -236,14 +234,13 @@ pub fn bucket_export(bucket_id: String, state: State<ServerState>) -> Result<Res
236234
let filename = format!("aw-bucket-export_{}.json", bucket_id);
237235

238236
let header_content = format!("attachment; filename={}", filename);
239-
let response = Response::build()
237+
Ok(Response::build()
240238
.status(Status::Ok)
241239
.header(Header::new("Content-Disposition", header_content))
242240
.sized_body(Cursor::new(
243241
serde_json::to_string(&export).expect("Failed to serialize"),
244242
))
245-
.finalize();
246-
return Ok(response);
243+
.finalize())
247244
}
248245

249246
#[delete("/<bucket_id>")]

aw-server/src/endpoints/cors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use rocket::http::Method;
2-
use rocket_cors;
32
use rocket_cors::{AllowedHeaders, AllowedOrigins};
43

54
use crate::config::AWConfig;
65

76
pub fn cors(config: &AWConfig) -> rocket_cors::Cors {
8-
let root_url = format!("http://127.0.0.1:{}", config.port).to_string();
9-
let root_url_localhost = format!("http://localhost:{}", config.port).to_string();
7+
let root_url = format!("http://127.0.0.1:{}", config.port);
8+
let root_url_localhost = format!("http://localhost:{}", config.port);
109
let mut allowed_exact_origins = vec![root_url, root_url_localhost];
1110
allowed_exact_origins.extend(config.cors.clone());
1211

aw-server/src/endpoints/export.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn buckets_export(state: State<ServerState>) -> Result<Response, Status> {
2626
export.buckets.insert(bid, bucket);
2727
}
2828

29-
let response = Response::build()
29+
Ok(Response::build()
3030
.status(Status::Ok)
3131
.header(Header::new(
3232
"Content-Disposition",
@@ -35,6 +35,5 @@ pub fn buckets_export(state: State<ServerState>) -> Result<Response, Status> {
3535
.sized_body(Cursor::new(
3636
serde_json::to_string(&export).expect("Failed to serialize"),
3737
))
38-
.finalize();
39-
return Ok(response);
38+
.finalize())
4039
}

aw-server/src/endpoints/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn bucket_import_form(
5050
.find(|&(k, _)| k == "boundary")
5151
.ok_or_else(|| {
5252
warn!("`Content-Type: multipart/form-data` boundary param not provided");
53-
return Status::BadRequest;
53+
Status::BadRequest
5454
})?;
5555

5656
let string = process_multipart_packets(boundary, data);

aw-server/src/endpoints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::PathBuf;
33
use std::sync::Mutex;
44

55
use gethostname::gethostname;
6-
use rocket;
76
use rocket::response::NamedFile;
87
use rocket::State;
98
use rocket_contrib::json::JsonValue;
@@ -88,6 +87,7 @@ fn get_device_id() -> String {
8887

8988
#[get("/")]
9089
fn server_info(config: State<AWConfig>) -> JsonValue {
90+
#[allow(clippy::or_fun_call)]
9191
let hostname = gethostname().into_string().unwrap_or("unknown".to_string());
9292
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
9393

aw-server/src/endpoints/query.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rocket_contrib::json::{Json, JsonValue};
66
use aw_models::Query;
77

88
use crate::endpoints::ServerState;
9-
use aw_query;
109
use aw_query::QueryError;
1110

1211
#[derive(Serialize)]

aw-server/src/endpoints/settings.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use aw_models::{Key, KeyValue};
1010
fn parse_key(key: String) -> Result<String, Status> {
1111
let namespace: String = "settings.".to_string();
1212
if key.len() >= 128 {
13-
return Err(Status::BadRequest);
13+
Err(Status::BadRequest)
1414
} else {
1515
Ok(namespace + key.as_str())
1616
}
@@ -24,13 +24,14 @@ pub fn setting_set(state: State<ServerState>, message: Json<KeyValue>) -> Result
2424

2525
let datastore: MutexGuard<'_, Datastore> = endpoints_get_lock!(state.datastore);
2626
let result = datastore.insert_key_value(&setting_key, &data.value);
27-
return match result {
27+
28+
match result {
2829
Ok(_) => Ok(Status::Created),
2930
Err(err) => {
3031
warn!("Unexpected error when creating setting: {:?}", err);
3132
Err(Status::InternalServerError)
3233
}
33-
};
34+
}
3435
}
3536

3637
#[get("/")]
@@ -49,22 +50,24 @@ pub fn settings_list_get(state: State<ServerState>) -> Result<Json<Vec<Key>>, St
4950
for i in queryresults? {
5051
output.push(Key { key: i });
5152
}
52-
return Ok(Json(output));
53+
54+
Ok(Json(output))
5355
}
5456

5557
#[get("/<key>")]
5658
pub fn setting_get(state: State<ServerState>, key: String) -> Result<Json<KeyValue>, Status> {
5759
let setting_key = parse_key(key)?;
5860

5961
let datastore = endpoints_get_lock!(state.datastore);
60-
return match datastore.get_key_value(&setting_key) {
62+
63+
match datastore.get_key_value(&setting_key) {
6164
Ok(result) => Ok(Json(result)),
6265
Err(DatastoreError::NoSuchKey) => Err(Status::NotFound),
6366
Err(err) => {
6467
warn!("Unexpected error when getting setting: {:?}", err);
6568
Err(Status::InternalServerError)
6669
}
67-
};
70+
}
6871
}
6972

7073
#[delete("/<key>")]
@@ -73,11 +76,12 @@ pub fn setting_delete(state: State<ServerState>, key: String) -> Result<(), Stat
7376

7477
let datastore = endpoints_get_lock!(state.datastore);
7578
let result = datastore.delete_key_value(&setting_key);
76-
return match result {
79+
80+
match result {
7781
Ok(_) => Ok(()),
7882
Err(err) => {
7983
warn!("Unexpected error when deleting setting: {:?}", err);
8084
Err(Status::InternalServerError)
8185
}
82-
};
86+
}
8387
}

aw-server/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern crate serde_derive;
1515

1616
extern crate chrono;
1717

18+
#[cfg(not(target_os = "android"))]
1819
extern crate appdirs;
1920

2021
#[cfg(target_os = "android")]

0 commit comments

Comments
 (0)