pub struct MethodResponse { /* private fields */ }server-core 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, streamed or not.
Sourcepub fn into_body(self) -> ResponseBody
pub fn into_body(self) -> ResponseBody
Consume the method response and return its body, whole or as a stream of parts.
Sourcepub async fn buffer(self) -> MethodResponse
pub async fn buffer(self) -> MethodResponse
Waits for the rest of a streamed response and returns it as a whole. Other responses are returned unchanged.
If the result fails or exceeds the response size limit after it started, the response is replaced with that error, because none of it was sent yet.
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,
) -> MethodResponse
pub fn subscription_response<T>( id: Id<'_>, result: ResponsePayload<'_, T>, max_response_size: usize, ) -> MethodResponse
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,
) -> MethodResponse
pub fn response<T>( id: Id<'_>, rp: ResponsePayload<'_, T>, max_response_size: usize, ) -> MethodResponse
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>>,
) -> MethodResponse
pub fn subscription_error<'a>( id: Id<'_>, err: impl Into<ErrorObject<'a>>, ) -> MethodResponse
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>>) -> MethodResponse
pub fn error<'a>(id: Id<'_>, err: impl Into<ErrorObject<'a>>) -> MethodResponse
Create a MethodResponse from a JSON-RPC error.
Sourcepub fn notification() -> MethodResponse
pub fn notification() -> MethodResponse
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 !RefUnwindSafe for MethodResponse
impl !Sync for MethodResponse
impl !UnwindSafe for MethodResponse
impl Forget for MethodResponse
impl Freeze for MethodResponse
impl Move for MethodResponse
impl Send for MethodResponse
impl Unpin for MethodResponse
impl UnsafeUnpin 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> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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: 48 bytes