[fractal] Backend: Use slices instead of references to immutable vectors where possible



commit 48ffd7bd6e732f5167137c9a152e1a4948941eac
Author: Alejandro Domínguez <adomu net-c com>
Date:   Sun Dec 30 02:05:21 2018 +0100

    Backend: Use slices instead of references to immutable vectors where possible

 fractal-matrix-api/src/backend/room.rs | 10 +++++-----
 fractal-matrix-api/src/backend/user.rs |  8 ++++----
 fractal-matrix-api/src/util.rs         | 15 +++++++--------
 3 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 573eaddf..c6164f69 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -180,7 +180,7 @@ fn parse_context(
     let url = client_url(
         &baseu,
         &format!("rooms/{}/context/{}", roomid, eid),
-        &vec![
+        &[
             ("limit", format!("{}", limit)),
             ("access_token", tk.clone()),
         ],
@@ -438,8 +438,8 @@ pub fn set_room_topic(bk: &Backend, roomid: &str, topic: &str) -> Result<(), Err
 pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), Error> {
     let baseu = bk.get_base_url()?;
     let tk = bk.data.lock().unwrap().access_token.clone();
-    let params = vec![("access_token", tk.clone())];
-    let mediaurl = media_url(&baseu, "upload", &params)?;
+    let params = &[("access_token", tk.clone())];
+    let mediaurl = media_url(&baseu, "upload", params)?;
     let roomurl = bk.url(&format!("rooms/{}/state/m.room.avatar", roomid), vec![])?;
 
     let mut file = File::open(&avatar)?;
@@ -482,8 +482,8 @@ pub fn attach_file(bk: &Backend, msg: Message) -> Result<(), Error> {
 
     let baseu = bk.get_base_url()?;
     let tk = bk.data.lock().unwrap().access_token.clone();
-    let params = vec![("access_token", tk.clone())];
-    let mediaurl = media_url(&baseu, "upload", &params)?;
+    let params = &[("access_token", tk.clone())];
+    let mediaurl = media_url(&baseu, "upload", params)?;
 
     let mut m = msg.clone();
     let tx = bk.tx.clone();
diff --git a/fractal-matrix-api/src/backend/user.rs b/fractal-matrix-api/src/backend/user.rs
index b1b0ea9c..768bb0c4 100644
--- a/fractal-matrix-api/src/backend/user.rs
+++ b/fractal-matrix-api/src/backend/user.rs
@@ -224,13 +224,13 @@ pub fn submit_phone_token(
     sid: String,
     token: String,
 ) -> Result<(), Error> {
-    let params = vec![
+    let params = &[
         ("sid", sid.clone()),
         ("client_secret", client_secret.clone()),
         ("token", token),
     ];
     let path = "/_matrix/identity/api/v1/validate/msisdn/submitToken";
-    let url = build_url(&Url::parse(&url)?, path, &params)?;
+    let url = build_url(&Url::parse(&url)?, path, params)?;
 
     let tx = bk.tx.clone();
     post!(
@@ -461,8 +461,8 @@ pub fn set_user_avatar(bk: &Backend, avatar: String) -> Result<(), Error> {
     let baseu = bk.get_base_url()?;
     let id = bk.data.lock().unwrap().user_id.clone();
     let tk = bk.data.lock().unwrap().access_token.clone();
-    let params = vec![("access_token", tk.clone())];
-    let mediaurl = media_url(&baseu, "upload", &params)?;
+    let params = &[("access_token", tk.clone())];
+    let mediaurl = media_url(&baseu, "upload", params)?;
     let url = bk.url(&format!("profile/{}/avatar_url", encode_uid(&id)), vec![])?;
 
     let mut file = File::open(&avatar)?;
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index a47d6ba7..c2a0fbf1 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -419,10 +419,10 @@ pub fn get_prev_batch_from(
     roomid: &str,
     evid: &str,
 ) -> Result<String, Error> {
-    let params = vec![("access_token", String::from(tk)), ("limit", 0.to_string())];
+    let params = &[("access_token", String::from(tk)), ("limit", 0.to_string())];
 
     let path = format!("rooms/{}/context/{}", roomid, evid);
-    let url = client_url(baseu, &path, &params)?;
+    let url = client_url(baseu, &path, params)?;
 
     let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?;
     let prev_batch = r["start"].to_string().trim_matches('"').to_string();
@@ -674,7 +674,7 @@ pub fn get_room_st(base: &Url, tk: &str, roomid: &str) -> Result<JsonValue, Erro
     let url = client_url(
         base,
         &format!("rooms/{}/state", roomid),
-        &vec![("access_token", String::from(tk))],
+        &[("access_token", String::from(tk))],
     )?;
 
     let attrs = json!(null);
@@ -791,17 +791,16 @@ pub fn fill_room_gap(
     let mut ms: Vec<Message> = vec![];
     let nend;
 
-    let mut params = vec![
+    let params = &[
         ("dir", String::from("f")),
         ("limit", format!("{}", globals::PAGE_LIMIT)),
         ("access_token", tk.clone()),
+        ("from", String::from(from)),
+        ("to", String::from(to)),
     ];
 
-    params.push(("from", String::from(from)));
-    params.push(("to", String::from(to)));
-
     let path = format!("rooms/{}/messages", roomid);
-    let url = client_url(baseu, &path, &params)?;
+    let url = client_url(baseu, &path, params)?;
 
     let r = json_q("get", &url, &json!(null), globals::TIMEOUT)?;
     nend = String::from(r["end"].as_str().unwrap_or_default());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]