Skip to content

Commit ad3b6d9

Browse files
committed
refactor: use to_owned instead of to_string
1 parent 8df09d1 commit ad3b6d9

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/api/ing/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn fmt_content(content: &str) -> String {
6464
.expect("Invalid regexp");
6565
}
6666
REGEX.captures(content).map_or_else(
67-
|| content.to_string(),
67+
|| content.to_owned(),
6868
|caps| {
6969
let at_user = caps.get(1).expect("No capture at index 1").as_str();
7070
REGEX.replace(content, at_user).to_string()
@@ -78,7 +78,7 @@ pub fn rm_ing_at_user_tag(text: &str) -> String {
7878
Regex::new(r#"<a.*href="https://home.cnblogs.com/u/.*?".*>(@.*?)</a>:"#)
7979
.expect("Invalid regexp");
8080
}
81-
REGEX.replace(text, "".to_string()).to_string()
81+
REGEX.replace(text, "").to_string()
8282
}
8383

8484
pub fn get_ing_at_user_tag_text(text: &str) -> String {
@@ -87,13 +87,10 @@ pub fn get_ing_at_user_tag_text(text: &str) -> String {
8787
Regex::new(r#"<a.*href="https://home.cnblogs.com/u/.*?".*>@(.*?)</a>:"#)
8888
.expect("Invalid regexp");
8989
}
90-
REGEX.captures(text).map_or_else(
91-
|| "".to_string(),
92-
|caps| {
93-
caps.get(1)
94-
.expect("No capture at index 1")
95-
.as_str()
96-
.to_string()
97-
},
98-
)
90+
REGEX.captures(text).map_or_else(String::new, |caps| {
91+
caps.get(1)
92+
.expect("No capture at index 1")
93+
.as_str()
94+
.to_string()
95+
})
9996
}

src/infra/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<K: ToString, V: ToString> VecExt for Vec<(K, V)> {
4545
let s_v = v.to_string();
4646
format!("{}={}", s_k, s_v)
4747
})
48-
.fold("".to_string(), |acc, q| format!("{acc}&{q}"))
48+
.fold(String::new(), |acc, q| format!("{acc}&{q}"))
4949
}
5050
}
5151

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn panic_if_err<T>(result: &Result<T>) {
5454
#[tokio::main(flavor = "multi_thread")]
5555
async fn main() -> Result<()> {
5656
let args_vec = env::args().collect::<Vec<_>>();
57-
if args_vec.iter().any(eq(&"--debug".to_string())) {
57+
if args_vec.iter().any(eq(&"--debug".to_owned())) {
5858
dbg!(args_vec);
5959
}
6060

0 commit comments

Comments
 (0)