Error handling 如何将关联类型绑定到“?”运算符?

Error handling 如何将关联类型绑定到“?”运算符?,error-handling,rust,associated-types,Error Handling,Rust,Associated Types,鉴于以下情况: struct; 易犯错误的特征{ 类型错误:输入; fn e(自我)->结果; } fn测试(f:&impl Fallible)->结果{ Ok(f.e()?) } 我试图表示,Fallible::Error类型可以转换为E,因此应该可以与?操作符一起使用。但是,由于某种原因,?是基于From特征的,我不确定是否可以绑定 此操作当前在以下情况下失败: error[E0277]: `?` couldn't convert the error to `E` --> src/

鉴于以下情况:

struct;
易犯错误的特征{
类型错误:输入;
fn e(自我)->结果;
}
fn测试(f:&impl Fallible)->结果{
Ok(f.e()?)
}
我试图表示,
Fallible::Error
类型可以转换为
E
,因此应该可以与
操作符一起使用。但是,由于某种原因,
是基于
From
特征的,我不确定是否可以绑定

此操作当前在以下情况下失败:

error[E0277]: `?` couldn't convert the error to `E`
 --> src/lib.rs:9:13
  |
9 |     Ok(f.e()?)
  |             ^ the trait `std::convert::From<<impl Fallible as Fallible>::Error>` is not implemented for `E`
  |
  = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
  = note: required by `std::convert::From::from`
错误[E0277]:`?`无法将错误转换为`E'`
-->src/lib.rs:9:13
|
9 |好(f.e()?)
|^E未实现特征'std::convert::From'`
|
=注意:问号操作(`?`)使用`From`特性隐式地对错误值执行转换
=注意:`std::convert::From::From'需要`

虽然不能在trait级别绑定,但可以在函数上绑定:

struct;
易犯错误的特征{
类型错误:输入;
fn e(自我)->结果;
}
fn测试(f:&T)->结果
哪里
T:Faileble,
E:从,
{
Ok(f.e()?)
}

关于《服务贸易总协定》将有助于解决这一问题的说法,我不太确定。你能澄清一下吗?@that3%如果你这样做,你会得到一个错误“关联类型的where子句不稳定”,并链接到GAT问题。