Skip to content

Commit

Permalink
refactor: use to_owned instead of to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaumy committed Sep 27, 2023
1 parent 8df09d1 commit ad3b6d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions src/api/ing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn fmt_content(content: &str) -> String {
.expect("Invalid regexp");
}
REGEX.captures(content).map_or_else(
|| content.to_string(),
|| content.to_owned(),
|caps| {
let at_user = caps.get(1).expect("No capture at index 1").as_str();
REGEX.replace(content, at_user).to_string()
Expand All @@ -78,7 +78,7 @@ pub fn rm_ing_at_user_tag(text: &str) -> String {
Regex::new(r#"<a.*href="https://home.cnblogs.com/u/.*?".*>(@.*?)</a>:"#)
.expect("Invalid regexp");
}
REGEX.replace(text, "".to_string()).to_string()
REGEX.replace(text, "").to_string()
}

pub fn get_ing_at_user_tag_text(text: &str) -> String {
Expand All @@ -87,13 +87,10 @@ pub fn get_ing_at_user_tag_text(text: &str) -> String {
Regex::new(r#"<a.*href="https://home.cnblogs.com/u/.*?".*>@(.*?)</a>:"#)
.expect("Invalid regexp");
}
REGEX.captures(text).map_or_else(
|| "".to_string(),
|caps| {
caps.get(1)
.expect("No capture at index 1")
.as_str()
.to_string()
},
)
REGEX.captures(text).map_or_else(String::new, |caps| {
caps.get(1)
.expect("No capture at index 1")
.as_str()
.to_string()
})
}
2 changes: 1 addition & 1 deletion src/infra/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<K: ToString, V: ToString> VecExt for Vec<(K, V)> {
let s_v = v.to_string();
format!("{}={}", s_k, s_v)
})
.fold("".to_string(), |acc, q| format!("{acc}&{q}"))
.fold(String::new(), |acc, q| format!("{acc}&{q}"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn panic_if_err<T>(result: &Result<T>) {
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()> {
let args_vec = env::args().collect::<Vec<_>>();
if args_vec.iter().any(eq(&"--debug".to_string())) {
if args_vec.iter().any(eq(&"--debug".to_owned())) {
dbg!(args_vec);
}

Expand Down

0 comments on commit ad3b6d9

Please sign in to comment.