How do I bubble up an error from the closure passed to regex::Regex::replace?
问题 I have a function which performs string replacement in-place via regex::Regex::replace via a closure which performs some operations on the Captures : pub fn solve_dice_expression(expression: String) -> Result<i64, Box<dyn Error>> { lazy_static! { static ref PATTERN: Regex = Regex::new(r"(\d+)d(\d+)").expect("Problem compiling regex"); } // For every match on the Dice expression regex, roll it in-place. let rolled_expression = PATTERN.replace(&expression, |caps: &Captures| { let diceroll_str =