Struct jsonrpsee_server::MethodResponse

source ·
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§

source§

impl MethodResponse

source

pub fn is_success(&self) -> bool

Returns whether the call was successful.

source

pub fn is_error(&self) -> bool

Returns whether the call failed.

source

pub fn is_subscription(&self) -> bool

Returns whether the response is a subscription response.

source

pub fn is_method_call(&self) -> bool

Returns whether the response is a method response.

source

pub fn is_batch(&self) -> bool

Returns whether the response is a batch response.

source

pub fn into_result(self) -> String

Consume the method response and extract the serialized response.

source

pub fn to_result(&self) -> String

Extract the serialized response as a String.

source

pub fn into_parts(self) -> (String, Option<MethodResponseNotifyTx>)

Consume the method response and extract the parts.

source

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

Get the error code

Returns Some(error code) if the call failed.

source

pub fn as_result(&self) -> &str

Get a reference to the serialized response.

source

pub fn from_batch(batch: BatchResponse) -> MethodResponse

Create a method response from BatchResponse.

source

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.

source

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.

source

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.

source

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

Create a MethodResponse from a JSON-RPC error.

source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a reference to the associated extensions.

source

pub fn with_extensions(self, extensions: Extensions) -> MethodResponse

Consumes the method response and returns a new one with the given extensions.

Trait Implementations§

source§

impl Debug for MethodResponse

source§

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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> MaybeSend for T
where T: Send,