fractal-matrix-api: More idiomatic if/else assignments

This fixes these errors from clippy:

```
error: `if _ { .. } else { .. }` is an expression
   --> fractal-matrix-api/src/util.rs:525:5
    |
525 | /     let path: String;
526 | |
527 | |     if thumb {
528 | |         params.push(("width", format!("{}", w)));
...   |
533 | |         path = format!("download/{}/{}", server, media);
534 | |     }
    | |_____^ help: it is more idiomatic to write: `let path = if thumb { ..; $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) ) } else { $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) ) };`
    |
    = note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_let_if_seq
```

Related: #370
This commit is contained in:
Zeeshan Ali 2018-12-12 23:05:44 +01:00 committed by Alexandre Franke
parent 01068ad752
commit b93f1e4420
2 changed files with 14 additions and 17 deletions

View file

@ -43,11 +43,10 @@ fn build_login_attrs(user: &str, password: &str) -> Result<JsonValue, Error> {
let emailre = Regex::new(
r"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])+@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$",
)?;
let attrs;
// Email
if emailre.is_match(&user) {
attrs = json!({
let attrs = if emailre.is_match(&user) {
json!({
"type": "m.login.password",
"password": password,
"initial_device_display_name": "Fractal",
@ -58,15 +57,15 @@ fn build_login_attrs(user: &str, password: &str) -> Result<JsonValue, Error> {
"medium": "email",
"address": user,
}
});
})
} else {
attrs = json!({
json!({
"type": "m.login.password",
"initial_device_display_name": "Fractal",
"user": user,
"password": password
});
}
})
};
Ok(attrs)
}

View file

@ -513,16 +513,15 @@ pub fn resolve_media_url(base: &Url, url: &str, thumb: bool, w: i32, h: i32) ->
let media = String::from(&caps["media"]);
let mut params: Vec<(&str, String)> = vec![];
let path: String;
if thumb {
let path = if thumb {
params.push(("width", format!("{}", w)));
params.push(("height", format!("{}", h)));
params.push(("method", String::from("scale")));
path = format!("thumbnail/{}/{}", server, media);
format!("thumbnail/{}/{}", server, media)
} else {
path = format!("download/{}/{}", server, media);
}
format!("download/{}/{}", server, media)
};
media_url(base, &path, &params)
}
@ -541,16 +540,15 @@ pub fn dw_media(
let media = String::from(&caps["media"]);
let mut params: Vec<(&str, String)> = vec![];
let path: String;
if thumb {
let path = if thumb {
params.push(("width", format!("{}", w)));
params.push(("height", format!("{}", h)));
params.push(("method", String::from("crop")));
path = format!("thumbnail/{}/{}", server, media);
format!("thumbnail/{}/{}", server, media)
} else {
path = format!("download/{}/{}", server, media);
}
format!("download/{}/{}", server, media)
};
let url = media_url(base, &path, &params)?;