advance/errors #766
Replies: 10 comments 19 replies
-
关于如何选用 thiserror 和 anyhow 只需要遵循一个原则即可:是否关注自定义错误消息,关注则使用 thiserror(常见业务代码),否则使用 anyhow(编写第三方库代码)。 这个位置是写错了吗,还是说我理解有误。 |
Beta Was this translation helpful? Give feedback.
-
#[derive(thiserror::Error, Debug)] 我不信强迫症内心毫无波澜 |
Beta Was this translation helpful? Give feedback.
-
对于返回的Result, 看到返回值有时候写作 |
Beta Was this translation helpful? Give feedback.
-
个人对这一段代码的理解: 采用短路求值的理解方式. 下面用 assert_eq!(s1.or(s2), s1); // Some1 or Some2 = Some1
assert_eq!(s1.or(n), s1); // Some or None = Some
assert_eq!(n.or(s1), s1); // None or Some = Some
assert_eq!(n.or(n), n); // None1 or None2 = None2 前面两个都是 后面两个是类似的, 然后
前两个 是 后面两个是 |
Beta Was this translation helpful? Give feedback.
-
晕了,这是什么。。 |
Beta Was this translation helpful? Give feedback.
-
为什么不讲一下anyhow得with_context,这样可以很快简化代码(建议) |
Beta Was this translation helpful? Give feedback.
-
为什么,这段代码在 fn render() -> Result<String, Box<dyn std::error::Error>> {
let file = std::env::var("MARKDOWN")?;
let source = read_to_string(file)?;
Ok(source)
}
// dyn error
#[test]
fn test_dyn_error() -> Result<(), Box<dyn std::error::Error>>{
let html = render()?;
println!("{}", html);
Ok(())
} 他会报String没有实现Read特征 error[E0277]: the trait bound `String: std::io::Read` is not satisfied
|
194 | let source = read_to_string(file)?;
| -------------- ^^^^ the trait `std::io::Read` is not implemented for `String`
| |
| required by a bound introduced by this call
| |
Beta Was this translation helpful? Give feedback.
-
使用 |
Beta Was this translation helpful? Give feedback.
-
归一化使用特征对象那一节中:
啊? 特征对象不就是接收实现了同个特征的对象而存在的吗,类似多态,不实现 |
Beta Was this translation helpful? Give feedback.
-
advance/errors
https://course.rs/advance/errors.html
Beta Was this translation helpful? Give feedback.
All reactions