mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
to contain String
This commit is contained in:
parent
96816a7b78
commit
2c09341074
|
@ -101,8 +101,6 @@ fn main() -> Result<ExitCode> {
|
||||||
info_file.final_message.unwrap_or_default(),
|
info_file.final_message.unwrap_or_default(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let replacer = UrlReplacer::new(&args.base_url);
|
|
||||||
|
|
||||||
// Show the welcome message if the state file doesn't exist yet.
|
// Show the welcome message if the state file doesn't exist yet.
|
||||||
if let Some(welcome_message) = info_file.welcome_message {
|
if let Some(welcome_message) = info_file.welcome_message {
|
||||||
match state_file_status {
|
match state_file_status {
|
||||||
|
@ -189,7 +187,12 @@ fn main() -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let hint = app_state.current_exercise().hint;
|
let hint = app_state.current_exercise().hint;
|
||||||
|
if let Some(base_url) = args.base_url {
|
||||||
|
let replacer = UrlReplacer::new(base_url);
|
||||||
println!("{}", replacer.replace(hint));
|
println!("{}", replacer.replace(hint));
|
||||||
|
} else {
|
||||||
|
println!("{}", hint);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// Handled in an earlier match.
|
// Handled in an earlier match.
|
||||||
Some(Subcommands::Init | Subcommands::Dev(_)) => (),
|
Some(Subcommands::Init | Subcommands::Dev(_)) => (),
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
pub struct UrlReplacer <'a> {
|
pub struct UrlReplacer {
|
||||||
base_url: &'a Option<String>
|
base_url: String
|
||||||
}
|
}
|
||||||
|
|
||||||
const EN_BASE_URL: &str = "https://doc.rust-lang.org/book";
|
const EN_BASE_URL: &str = "https://doc.rust-lang.org/book";
|
||||||
|
|
||||||
impl <'a> UrlReplacer <'a> {
|
impl UrlReplacer {
|
||||||
pub fn new(base_url: &'a Option<String>) -> Self {
|
pub fn new(base_url: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base_url
|
base_url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace(&self, hint: &str) -> String {
|
pub fn replace(&self, hint: &str) -> String {
|
||||||
if let Some(base_url) = self.base_url {
|
hint.replace(EN_BASE_URL, &self.base_url)
|
||||||
hint.replace(EN_BASE_URL, base_url)
|
|
||||||
} else {
|
|
||||||
hint.to_owned()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue