diff --git a/src/app_state.rs b/src/app_state.rs index 373a9872..e8d1bd1a 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -83,11 +83,9 @@ impl AppState { })?; // replacer for rustbook url - let url_replacer = if let Some(url) = &base_url { - Some(UrlReplacer::new(&url)) - } else { - None - }; + let url_replacer = base_url.as_ref().map(|url| { + UrlReplacer::new(url) + }); let dir_canonical_path = term::canonicalize("exercises"); let mut exercises = exercise_infos @@ -102,7 +100,7 @@ impl AppState { let mut hint = exercise_info.hint.leak().trim_ascii(); if let Some(replacer) = &url_replacer { - hint = replacer.replace(&hint).leak(); + hint = replacer.replace(hint).leak(); } let canonical_path = dir_canonical_path.as_deref().map(|dir_canonical_path| { diff --git a/src/url_replacer.rs b/src/url_replacer.rs index 6a4aac45..0499372f 100644 --- a/src/url_replacer.rs +++ b/src/url_replacer.rs @@ -6,11 +6,11 @@ const EN_BASE_URL: &str = "https://doc.rust-lang.org/book"; impl UrlReplacer { /// this fn will trim url end with '/' - pub fn new(base_url: &String) -> Self { + pub fn new(base_url: &str) -> Self { let url = if base_url.ends_with('/') { base_url.trim_end_matches('/').to_owned() } else { - base_url.clone() + base_url.to_owned() }; Self {