pub enum JsonRpcResponse<T> {
Success(JsonRpcSuccessResponse<T>),
Error(JsonRpcErrorResponse),
}Expand description
A JSON-RPC 2.0 response: either a success with a result or an error with
an error object.
Deliberately not #[non_exhaustive]: JSON-RPC 2.0 fixes a response to
exactly these two shapes, so consumers may match them exhaustively.
§Deserialization
Deserialization is hand-written rather than #[serde(untagged)], and it
enforces JSON-RPC 2.0 §5: a response object must carry exactly one of
result or error. A message with both — or neither — is rejected. (A
naïve untagged union tries Success first and would silently read a
malformed result+error message as a success, discarding the error.)
When result is present but fails to typecheck as T, the underlying
type error is surfaced verbatim instead of an opaque “did not match any
variant” message.
Serialization keeps the untagged shape (the bare success/error object, no enum tag), matching the JSON-RPC wire format.
Variants§
Success(JsonRpcSuccessResponse<T>)
Successful response carrying a typed result.
Error(JsonRpcErrorResponse)
Error response carrying a structured error object.
Trait Implementations§
Source§impl<T> Clone for JsonRpcResponse<T>where
T: Clone,
impl<T> Clone for JsonRpcResponse<T>where
T: Clone,
Source§fn clone(&self) -> JsonRpcResponse<T>
fn clone(&self) -> JsonRpcResponse<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for JsonRpcResponse<T>where
T: Debug,
impl<T> Debug for JsonRpcResponse<T>where
T: Debug,
Source§impl<'de, T> Deserialize<'de> for JsonRpcResponse<T>where
T: DeserializeOwned,
impl<'de, T> Deserialize<'de> for JsonRpcResponse<T>where
T: DeserializeOwned,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<JsonRpcResponse<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<JsonRpcResponse<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> Serialize for JsonRpcResponse<T>where
T: Serialize,
impl<T> Serialize for JsonRpcResponse<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl<T> Freeze for JsonRpcResponse<T>where
T: Freeze,
impl<T> RefUnwindSafe for JsonRpcResponse<T>where
T: RefUnwindSafe,
impl<T> Send for JsonRpcResponse<T>where
T: Send,
impl<T> Sync for JsonRpcResponse<T>where
T: Sync,
impl<T> Unpin for JsonRpcResponse<T>where
T: Unpin,
impl<T> UnsafeUnpin for JsonRpcResponse<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for JsonRpcResponse<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request