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_json(self) -> String
pub fn into_json(self) -> String
Consume the method response and extract the serialized JSON response.
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 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 notification() -> Self
pub fn notification() -> Self
Create notification response which is a response that doesn’t expect a reply.
Trait Implementations§
Source§impl AsRef<str> for MethodResponse
impl AsRef<str> for MethodResponse
Source§impl Debug for MethodResponse
impl Debug for MethodResponse
Auto Trait Implementations§
impl Freeze for MethodResponse
impl RefUnwindSafe for MethodResponse
impl Send for MethodResponse
impl Sync for MethodResponse
impl Unpin for MethodResponse
impl UnsafeUnpin for MethodResponse
impl UnwindSafe for MethodResponse
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 40 bytes