Type error when implementing TryFrom trait

Viewed 1002

I am trying to implement std::convert::TryFrom<OutputMessage> for warp::filters::ws::Message where OutputMessage is a simple struct that can be serialized with 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(());
            }
        }
    }
}

However, I'm getting the following errors for the function signature:

method `try_from` has an incompatible type for trait
expected fn pointer `fn(protocol::Output) -> Result<_, ()>`
found fn pointer `fn(protocol::Output) -> Result<_, Infallible>`

And this one for the returned Err(()):

mismatched types
expected enum `Infallible`, found `()`

Is there any way to make this implementation work, maybe by changing it's Error type? Or is this kind of trait implementation not really possible?

0 Answers
Related