Toast message when scheduling a recipe
This commit is contained in:
parent
fbef990022
commit
ccb1248da3
11 changed files with 168 additions and 66 deletions
|
|
@ -183,6 +183,12 @@ pub struct ScheduleRecipe {
|
|||
pub servings: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum ScheduleRecipeResult {
|
||||
Ok,
|
||||
RecipeAlreadyScheduledAtThisDate,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ScheduledRecipe {
|
||||
pub recipe_id: i64,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,18 @@ pub fn substitute(str: &str, pattern: &str, replacements: &[&str]) -> String {
|
|||
result
|
||||
}
|
||||
|
||||
/// Example: substitute_with_names("{hello}, {world}!", &["{hello}", "{world"], &["Hello", "World"])
|
||||
pub fn substitute_with_names(str: &str, names: &[&str], replacements: &[&str]) -> String {
|
||||
let mut result = str.to_string();
|
||||
for (i, name) in names.iter().enumerate() {
|
||||
if i >= replacements.len() {
|
||||
break;
|
||||
}
|
||||
result = result.replace(name, replacements[i]);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -52,4 +64,36 @@ mod tests {
|
|||
assert_eq!(substitute("{}{}{}", "{}", &["a", "bc", "def"]), "abcdef");
|
||||
assert_eq!(substitute("{}{}{}", "{}", &["a"]), "a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_substitute_with_names() {
|
||||
assert_eq!(
|
||||
substitute_with_names("{hello}, {world}!", &["{hello}"], &["Hello", "World"]),
|
||||
"Hello, {world}!"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
substitute_with_names("{hello}, {world}!", &[], &["Hello", "World"]),
|
||||
"{hello}, {world}!"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
substitute_with_names("{hello}, {world}!", &["{hello}", "{world}"], &["Hello"]),
|
||||
"Hello, {world}!"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
substitute_with_names("{hello}, {world}!", &["{hello}", "{world}"], &[]),
|
||||
"{hello}, {world}!"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
substitute_with_names(
|
||||
"{hello}, {world}!",
|
||||
&["{hello}", "{world}"],
|
||||
&["Hello", "World"]
|
||||
),
|
||||
"Hello, World!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue