Struct jsonrpsee_core::server::MethodResponse
source · pub struct MethodResponse { /* private fields */ }
server
only.Expand description
Represents a response to a method call.
NOTE: A subscription is also a method call but it’s
possible determine whether a method response
is “subscription” or “ordinary method call”
by calling MethodResponse::is_subscription
Implementations§
source§impl MethodResponse
impl MethodResponse
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns whether the call was successful.
sourcepub fn is_subscription(&self) -> bool
pub fn is_subscription(&self) -> bool
Returns whether the response is a subscription response.
sourcepub fn is_method_call(&self) -> bool
pub fn is_method_call(&self) -> bool
Returns whether the response is a method response.
sourcepub fn into_result(self) -> String
pub fn into_result(self) -> String
Consume the method response and extract the serialized response.
sourcepub fn into_parts(self) -> (String, Option<MethodResponseNotifyTx>)
pub fn into_parts(self) -> (String, Option<MethodResponseNotifyTx>)
Consume the method response and extract the parts.
sourcepub fn as_error_code(&self) -> Option<i32>
pub fn as_error_code(&self) -> Option<i32>
Get the error code
Returns Some(error code)
if the call failed.
sourcepub fn from_batch(batch: BatchResponse) -> Self
pub fn from_batch(batch: BatchResponse) -> Self
Create a method response from BatchResponse
.
sourcepub fn subscription_response<T>(
id: Id<'_>,
result: ResponsePayload<'_, T>,
max_response_size: usize,
) -> Self
pub fn subscription_response<T>( id: Id<'_>, result: ResponsePayload<'_, T>, max_response_size: usize, ) -> Self
This is similar to MethodResponse::response
but sets a flag to indicate
that response is a subscription.
sourcepub fn response<T>(
id: Id<'_>,
rp: ResponsePayload<'_, T>,
max_response_size: usize,
) -> Self
pub fn response<T>( id: Id<'_>, rp: ResponsePayload<'_, T>, max_response_size: usize, ) -> Self
Create a new method response.
If the serialization of result
exceeds max_response_size
then
the response is changed to an JSON-RPC error object.
sourcepub fn subscription_error<'a>(
id: Id<'_>,
err: impl Into<ErrorObject<'a>>,
) -> Self
pub fn subscription_error<'a>( id: Id<'_>, err: impl Into<ErrorObject<'a>>, ) -> Self
This is similar to MethodResponse::error
but sets a flag to indicate
that error is a subscription.
sourcepub fn error<'a>(id: Id<'_>, err: impl Into<ErrorObject<'a>>) -> Self
pub fn error<'a>(id: Id<'_>, err: impl Into<ErrorObject<'a>>) -> Self
Create a MethodResponse
from a JSON-RPC error.
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a reference to the associated extensions.
sourcepub fn with_extensions(self, extensions: Extensions) -> Self
pub fn with_extensions(self, extensions: Extensions) -> Self
Consumes the method response and returns a new one with the given extensions.