我目前必须使用它来格式化 .expect()
消息:
fn main() {
let x: Option<&str> = None;
x.expect(&format!("the world is ending: {}", "foo")[..]);
}
有没有更简洁的方法?
最佳答案
我会这样做:
option.unwrap_or_else(|| panic!("ah: {}", "nuts"))
格式化一个字符串的代价有点大。除非确实需要,否则这将避免格式化字符串。
关于rust - 有没有更简洁的方法来格式化 .expect() 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55513198/