以下代码
fn get_issues(addr: &str) -> Result<(), std::error::Error> {
let mut result = String::new();
reqwest::get(&format!("{}/issues", addr))?.read_to_string(&mut result)?;
unimplemented!();
}
产量
error[E0277]: the trait bound `std::error::Error + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:37:1
|
37 | / fn get_issues(addr: &str) -> Result<(), std::error::Error> {
38 | | let mut result = String::new();
39 | | reqwest::get(&format!("{}/issues", addr))?.read_to_string(&mut result)?;
40 | |
41 | | unimplemented!();
42 | | }
| |_^ `std::error::Error + 'static` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `std::error::Error + 'static`
= note: required by `std::result::Result`
但是,reqwest::get()
返回Result<.., reqwest::Error>
,read_to_string()
返回Result<.., std::io::Error>
。我想使用某种常见的错误类型来避免类型错误。
我可以使用某种错误类型使get_issues
按原样工作,还是需要将错误转换为我自己的错误类型?