rustlings/src/url_replacer.rs

22 lines
473 B
Rust
Raw Normal View History

2024-12-07 12:40:18 +00:00
pub struct UrlReplacer <'a> {
base_url: &'a Option<String>
}
const EN_BASE_URL: &str = "https://doc.rust-lang.org/book";
impl <'a> UrlReplacer <'a> {
pub fn new(base_url: &'a Option<String>) -> Self {
Self {
base_url
}
}
pub fn replace(&self, hint: &str) -> String {
if let Some(base_url) = self.base_url {
hint.replace(EN_BASE_URL, base_url)
} else {
hint.to_owned()
}
}
}