pub fn reply_result(
frame: &str,
expected: &RequestId,
) -> Result<JsonObject, RequestError>Expand description
The result out of a reply frame, if that frame is this request’s answer.
§Errors
RequestError::UnreadableFrame when the frame is not JSON, or not an
object; RequestError::IdMismatch when it answers a different request;
RequestError::MissingResult when it is neither a result nor an error;
RequestError::ResultNotAnObject when the result is not an object; and
RequestError::PeerError when the peer reported a failure, which is the
one of these a caller can act on by changing what it asked for.
The id comparison is the reason this takes expected rather than reading
the frame’s own: a stream carrying notifications as well as replies hands
the caller frames in an order they did not choose.
§Examples
use protocol_droid::application::jsonrpc::document::reply_result;
use protocol_droid::domain::RequestId;
let frame = r#"{"id":1,"jsonrpc":"2.0","result":{"tools":[]}}"#;
let result = reply_result(frame, &RequestId::number(1))?;
assert_eq!(result.as_str(), r#"{"tools":[]}"#);