I have the following code, where msg
is a websocket message that may be convertible to a string:
let str_result = msg.to_str();
let result = str_result.map_or(Err(XXX), serde_json::from_str::<TargetType>);
The problem with this code is that to_str
returns a Result<&str, ()>
while serde_json::from_str
returns a Result<TargetType, serde_json::error::Error>
. Is there an elegant way that I can convert the error from to_str
into a serde_json::error::Error
, e.g., an EOF error?
Is there a better approach to solving this problem in general that I am missing?