我正在尝试实现std::convert::TryFrom<OutputMessage>wherewarp::filters::ws::Message是OutputMessage一个可以序列化的简单结构serde_json::to_string():
impl TryFrom<OutputMessage> for Message {
type Error = ();
fn try_from(output_message: OutputMessage) -> Result<Self, <Self as TryFrom<Message>>::Error> {
match serde_json::to_string(&output_message) {
Ok(output_string) => Ok(Message::text(output_string)),
Err(err) => {
return Err(());
}
}
}
}
但是,函数签名出现以下错误:
method `try_from` has an incompatible type for trait
expected fn pointer `fn(protocol::Output) -> Result<_, ()>`
found fn pointer `fn(protocol::Output) -> Result<_, Infallible>`
而这个是返回的Err(()):
mismatched types
expected enum `Infallible`, found `()`
有没有办法使这个实现工作,也许通过改变它的Error类型?或者这种特质实现真的不可能吗?