Skip to main content

MethodResponse

Struct MethodResponse 

pub struct MethodResponse { /* private fields */ }
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§

§

impl MethodResponse

pub fn is_success(&self) -> bool

Returns whether the call was successful.

pub fn is_error(&self) -> bool

Returns whether the call failed.

pub fn is_subscription(&self) -> bool

Returns whether the response is a subscription response.

pub fn is_method_call(&self) -> bool

Returns whether the response is a method response.

pub fn is_batch(&self) -> bool

Returns whether the response is a batch response.

pub fn into_json(self) -> String

Consume the method response and extract the serialized JSON response.

pub fn to_json(&self) -> String

Get the serialized JSON response.

pub fn as_error_code(&self) -> Option<i32>

Get the error code

Returns Some(error code) if the call failed.

pub fn subscription_response<T>( id: Id<'_>, result: ResponsePayload<'_, T>, max_response_size: usize, ) -> MethodResponse
where T: Serialize + Clone,

This is similar to MethodResponse::response but sets a flag to indicate that response is a subscription.

pub fn response<T>( id: Id<'_>, rp: ResponsePayload<'_, T>, max_response_size: usize, ) -> MethodResponse
where T: Serialize + Clone,

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.

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.

pub fn error<'a>(id: Id<'_>, err: impl Into<ErrorObject<'a>>) -> MethodResponse

Create a MethodResponse from a JSON-RPC error.

pub fn notification() -> MethodResponse

Create notification response which is a response that doesn’t expect a reply.

Trait Implementations§

§

impl AsRef<str> for MethodResponse

§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Debug for MethodResponse

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Display for MethodResponse

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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