[fractal] Call String::new() instead of String::from("") or "".to_string()
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Call String::new() instead of String::from("") or "".to_string()
- Date: Sun, 6 Jan 2019 17:49:51 +0000 (UTC)
commit 043e7f5d44a29a14aa16004fe3e969884ee1bc17
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Sun Jan 6 16:45:40 2019 +0100
Call String::new() instead of String::from("") or "".to_string()
fractal-gtk/src/app/connect/directory.rs | 4 ++--
fractal-gtk/src/appop/directory.rs | 8 ++++----
fractal-gtk/src/appop/invite.rs | 2 +-
fractal-gtk/src/appop/login.rs | 6 +++---
fractal-gtk/src/appop/message.rs | 2 +-
fractal-gtk/src/appop/notify.rs | 2 +-
fractal-gtk/src/appop/room.rs | 12 ++++--------
fractal-gtk/src/widgets/avatar.rs | 4 ++--
fractal-gtk/src/widgets/roomlist.rs | 2 +-
fractal-matrix-api/src/backend/directory.rs | 2 +-
fractal-matrix-api/src/backend/media.rs | 8 ++++----
fractal-matrix-api/src/backend/mod.rs | 6 +++---
fractal-matrix-api/src/backend/room.rs | 2 +-
fractal-matrix-api/src/backend/stickers.rs | 2 +-
fractal-matrix-api/src/backend/user.rs | 4 ++--
fractal-matrix-api/src/model/message.rs | 2 +-
fractal-matrix-api/src/util.rs | 8 ++++----
17 files changed, 36 insertions(+), 40 deletions(-)
---
diff --git a/fractal-gtk/src/app/connect/directory.rs b/fractal-gtk/src/app/connect/directory.rs
index f7da1124..a2c86830 100644
--- a/fractal-gtk/src/app/connect/directory.rs
+++ b/fractal-gtk/src/app/connect/directory.rs
@@ -139,7 +139,7 @@ impl App {
let v = protocol_model.get_value(&it, 0);
v.get().unwrap()
}
- None => String::from(""),
+ None => String::new(),
};
directory_choice_label.set_text(&protocol);
@@ -153,7 +153,7 @@ impl App {
let v = protocol_model.get_value(&it, 0);
v.get().unwrap()
}
- None => String::from(""),
+ None => String::new(),
};
directory_choice_label.set_text(&protocol);
diff --git a/fractal-gtk/src/appop/directory.rs b/fractal-gtk/src/appop/directory.rs
index d2f14965..a868ebf9 100644
--- a/fractal-gtk/src/appop/directory.rs
+++ b/fractal-gtk/src/appop/directory.rs
@@ -54,10 +54,10 @@ impl AppOp {
let v = protocol_model.get_value(&it, 1);
v.get().unwrap()
}
- None => String::from(""),
+ None => String::new(),
}
} else {
- String::from("")
+ String::new()
};
let q = self
@@ -81,10 +81,10 @@ impl AppOp {
let homeserver = if other_homeserver_radio.get_active() {
other_homeserver_url.get_text()
} else if protocol == "matrix.org" {
- protocol = String::from("");
+ protocol = String::new();
String::from("matrix.org")
} else {
- String::from("")
+ String::new()
};
if !more {
diff --git a/fractal-gtk/src/appop/invite.rs b/fractal-gtk/src/appop/invite.rs
index 7b666661..0694546c 100644
--- a/fractal-gtk/src/appop/invite.rs
+++ b/fractal-gtk/src/appop/invite.rs
@@ -232,7 +232,7 @@ impl AppOp {
.get_object::<gtk::MessageDialog>("invite_dialog")
.expect("Can't find invite_dialog in ui file.");
- let empty = String::from("");
+ let empty = String::new();
let room_name = room_name.unwrap_or(&empty);
let title = i18n_k("Join {room_name}?", &[("room_name", &room_name)]);
let secondary;
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 08122cfb..952ae12c 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -208,15 +208,15 @@ impl AppOp {
let username = match user_entry.get_text() {
Some(s) => s,
- None => String::from(""),
+ None => String::new(),
};
let password = match pass_entry.get_text() {
Some(s) => s,
- None => String::from(""),
+ None => String::new(),
};
let passconf = match pass_conf.get_text() {
Some(s) => s,
- None => String::from(""),
+ None => String::new(),
};
if password != passconf {
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 948b8429..46008223 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -494,7 +494,7 @@ fn create_ui_message(
) -> MessageContent {
MessageContent {
msg: msg.clone(),
- id: msg.id.unwrap_or(String::from("")),
+ id: msg.id.unwrap_or(String::new()),
sender: msg.sender,
sender_name: name,
mtype: t,
diff --git a/fractal-gtk/src/appop/notify.rs b/fractal-gtk/src/appop/notify.rs
index 4fe495c0..ceec8b5c 100644
--- a/fractal-gtk/src/appop/notify.rs
+++ b/fractal-gtk/src/appop/notify.rs
@@ -51,7 +51,7 @@ impl AppOp {
if let Some(name) = r.name.clone() {
format!(" ({})", name)
} else {
- String::from("")
+ String::new()
}
};
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 87e0186d..8ef1348b 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -226,7 +226,7 @@ impl AppOp {
.get_object::<gtk::ToggleButton>("private_visibility_button")
.expect("Can't find private_visibility_button in ui file.");
- let n = name.get_text().unwrap_or(String::from(""));
+ let n = name.get_text().unwrap_or(String::new());
// Since the switcher
let p = if private.get_active() {
@@ -401,11 +401,7 @@ impl AppOp {
.get_object::<gtk::Entry>("join_room_name")
.expect("Can't find join_room_name in ui file.");
- let n = name
- .get_text()
- .unwrap_or(String::from(""))
- .trim()
- .to_string();
+ let n = name.get_text().unwrap_or(String::new()).trim().to_string();
self.backend.send(BKCommand::JoinRoom(n.clone())).unwrap();
}
@@ -454,12 +450,12 @@ impl AppOp {
let m1 = match members.next() {
Some((_uid, m)) => m.get_alias(),
- None => "".to_string(),
+ None => String::new(),
};
let m2 = match members.next() {
Some((_uid, m)) => m.get_alias(),
- None => "".to_string(),
+ None => String::new(),
};
let name = match n {
diff --git a/fractal-gtk/src/widgets/avatar.rs b/fractal-gtk/src/widgets/avatar.rs
index a9875aac..bed70abf 100644
--- a/fractal-gtk/src/widgets/avatar.rs
+++ b/fractal-gtk/src/widgets/avatar.rs
@@ -32,7 +32,7 @@ impl AvatarData {
}
pub fn redraw_pixbuf(&mut self) {
- let path = cache_path(&self.uid).unwrap_or(String::from(""));
+ let path = cache_path(&self.uid).unwrap_or(String::new());
self.cache = load_pixbuf(&path, self.size);
self.widget.queue_draw();
}
@@ -77,7 +77,7 @@ impl AvatarExt for gtk::Box {
fn circle(&self, uid: String, username: Option<String>, size: i32) -> Rc<RefCell<AvatarData>> {
self.clean();
let da = self.create_da(Some(size));
- let path = cache_path(&uid).unwrap_or(String::from(""));
+ let path = cache_path(&uid).unwrap_or(String::new());
let user_avatar = load_pixbuf(&path, size);
let uname = username.clone();
/* remove IRC postfix from the username */
diff --git a/fractal-gtk/src/widgets/roomlist.rs b/fractal-gtk/src/widgets/roomlist.rs
index 84497b80..ef93fdb6 100644
--- a/fractal-gtk/src/widgets/roomlist.rs
+++ b/fractal-gtk/src/widgets/roomlist.rs
@@ -360,7 +360,7 @@ impl RoomListGroup {
if let Some(row) = self.list.get_row_at_index(i as i32) {
match term {
&Some(ref t) if !t.is_empty() => {
- let rname = r.room.name.clone().unwrap_or("".to_string()).to_lowercase();
+ let rname = r.room.name.clone().unwrap_or(String::new()).to_lowercase();
if rname.contains(&t.to_lowercase()) {
row.show();
} else {
diff --git a/fractal-matrix-api/src/backend/directory.rs b/fractal-matrix-api/src/backend/directory.rs
index b2ab0895..bf2107c2 100644
--- a/fractal-matrix-api/src/backend/directory.rs
+++ b/fractal-matrix-api/src/backend/directory.rs
@@ -32,7 +32,7 @@ pub fn protocols(bk: &Backend) -> Result<(), Error> {
let mut protocols: Vec<Protocol> = vec![];
protocols.push(Protocol {
- id: String::from(""),
+ id: String::new(),
desc: String::from(s.split('/').last().unwrap_or("")),
});
diff --git a/fractal-matrix-api/src/backend/media.rs b/fractal-matrix-api/src/backend/media.rs
index 1f1b57bf..1f0050c5 100644
--- a/fractal-matrix-api/src/backend/media.rs
+++ b/fractal-matrix-api/src/backend/media.rs
@@ -24,7 +24,7 @@ pub fn get_thumb_async(bk: &Backend, media: String, tx: Sender<String>) -> Resul
tx.send(fname).unwrap();
}
Err(_) => {
- tx.send(String::from("")).unwrap();
+ tx.send(String::new()).unwrap();
}
};
});
@@ -41,7 +41,7 @@ pub fn get_media_async(bk: &Backend, media: String, tx: Sender<String>) -> Resul
tx.send(fname).unwrap();
}
Err(_) => {
- tx.send(String::from("")).unwrap();
+ tx.send(String::new()).unwrap();
}
};
});
@@ -106,7 +106,7 @@ pub fn get_media_url(bk: &Backend, media: String, tx: Sender<String>) -> Result<
tx.send(uri.to_string()).unwrap();
}
Err(_) => {
- tx.send(String::from("")).unwrap();
+ tx.send(String::new()).unwrap();
}
};
});
@@ -127,7 +127,7 @@ pub fn get_file_async(url: String, tx: Sender<String>) -> Result<(), Error> {
tx.send(fname).unwrap();
}
Err(_) => {
- tx.send(String::from("")).unwrap();
+ tx.send(String::new()).unwrap();
}
};
});
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index abd9f8d1..0d75f7d8 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -33,14 +33,14 @@ impl Backend {
pub fn new(tx: Sender<BKResponse>) -> Backend {
let data = BackendData {
user_id: String::from("Guest"),
- access_token: String::from(""),
+ access_token: String::new(),
server_url: String::from("https://matrix.org"),
scalar_token: None,
scalar_url: String::from("https://scalar.vector.im"),
sticker_widget: None,
since: None,
- rooms_since: String::from(""),
- join_to_room: String::from(""),
+ rooms_since: String::new(),
+ join_to_room: String::new(),
m_direct: HashMap::new(),
};
Backend {
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 6f1a8c6f..7099fca3 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -71,7 +71,7 @@ pub fn get_room_avatar(bk: &Backend, roomid: String) -> Result<(), Error> {
if let Ok(dest) = cache_path(&roomid) {
thumb(&baseu, u, Some(&dest)).unwrap_or_default()
} else {
- String::from("")
+ String::new()
}
}
None => util::get_room_avatar(&baseu, &tk, &userid, &roomid).unwrap_or_default(),
diff --git a/fractal-matrix-api/src/backend/stickers.rs b/fractal-matrix-api/src/backend/stickers.rs
index e459144b..b49c0bd9 100644
--- a/fractal-matrix-api/src/backend/stickers.rs
+++ b/fractal-matrix-api/src/backend/stickers.rs
@@ -64,7 +64,7 @@ pub fn get_sticker_widget_id(bk: &Backend, then: BKCommand) -> Result<(), Error>
let url = vurl(&d, "widgets/request", &[]).unwrap();
match json_q("post", &url, &data, globals::TIMEOUT) {
Ok(r) => {
- let mut id = "".to_string();
+ let mut id = String::new();
if let Some(i) = r["id"].as_str() {
id = i.to_string();
}
diff --git a/fractal-matrix-api/src/backend/user.rs b/fractal-matrix-api/src/backend/user.rs
index 1d73ed7b..84d959a1 100644
--- a/fractal-matrix-api/src/backend/user.rs
+++ b/fractal-matrix-api/src/backend/user.rs
@@ -75,7 +75,7 @@ pub fn get_threepid(bk: &Backend) -> Result<(), Error> {
if let Some(arr) = r["threepids"].as_array() {
for pid in arr.iter() {
let address = match pid["address"].as_str() {
- None => "".to_string(),
+ None => String::new(),
Some(a) => a.to_string(),
};
let add = match pid["added_at"].as_u64() {
@@ -83,7 +83,7 @@ pub fn get_threepid(bk: &Backend) -> Result<(), Error> {
Some(a) => a,
};
let medium = match pid["medium"].as_str() {
- None => "".to_string(),
+ None => String::new(),
Some(a) => a.to_string(),
};
let val = match pid["validated_at"].as_u64() {
diff --git a/fractal-matrix-api/src/model/message.rs b/fractal-matrix-api/src/model/message.rs
index d6409166..280cb4b2 100644
--- a/fractal-matrix-api/src/model/message.rs
+++ b/fractal-matrix-api/src/model/message.rs
@@ -126,7 +126,7 @@ impl Message {
room: String::from(roomid),
id: Some(id.to_string()),
mtype: type_.to_string(),
- body: "".to_string(),
+ body: String::new(),
url: None,
thumb: None,
formatted_body: None,
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index 885f7781..c91789e6 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -669,10 +669,10 @@ pub fn get_user_avatar(baseu: &Url, userid: &str) -> Result<(String, String), Er
let img = thumb(baseu, &url, Some(&dest))?;
Ok((name.clone(), img))
}
- None => Ok((name.clone(), String::from(""))),
+ None => Ok((name.clone(), String::new())),
}
}
- Err(_) => Ok((String::from(userid), String::from(""))),
+ Err(_) => Ok((String::from(userid), String::new())),
}
}
@@ -718,7 +718,7 @@ pub fn get_room_avatar(base: &Url, tk: &str, userid: &str, roomid: &str) -> Resu
};
if fname.is_empty() {
- fname = String::from("");
+ fname = String::new();
}
Ok(fname)
@@ -896,7 +896,7 @@ pub fn cache_dir_path(dir: &str, name: &str) -> Result<String, Error> {
pub fn get_user_avatar_img(baseu: &Url, userid: &str, avatar: &str) -> Result<String, Error> {
if avatar.is_empty() {
- return Ok(String::from(""));
+ return Ok(String::new());
}
let dest = cache_path(&userid)?;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]