alloy_json_rpc

Struct Request

Source
pub struct Request<Params> {
    pub meta: RequestMeta,
    pub params: Params,
}
Expand description

A JSON-RPC 2.0 request object.

This is a generic type that can be used to represent any JSON-RPC request. The Params type parameter is used to represent the parameters of the request, and the method field is used to represent the method name.

§Note

The value of method should be known at compile time.

Fields§

§meta: RequestMeta

The request metadata (ID and method).

§params: Params

The request parameters.

Implementations§

Source§

impl<Params> Request<Params>

Source

pub fn new(method: impl Into<Cow<'static, str>>, id: Id, params: Params) -> Self

Create a new Request.

Source

pub fn is_subscription(&self) -> bool

Returns true if the request is a subscription.

Source

pub fn set_is_subscription(&mut self)

Indicates that the request is a non-standard subscription (i.e. not “eth_subscribe”).

Source

pub fn set_subscription_status(&mut self, sub: bool)

Setter for is_subscription. Indicates to RPC clients that the request triggers a stream of notifications.

Source

pub fn map_params<NewParams>( self, map: impl FnOnce(Params) -> NewParams, ) -> Request<NewParams>

Change type of the request parameters.

Source§

impl<Params> Request<Params>
where Params: RpcParam,

Source

pub fn box_params(self) -> PartiallySerializedRequest

Serialize the request parameters as a boxed RawValue.

§Panics

If serialization of the params fails.

Source

pub fn serialize(self) -> Result<SerializedRequest>

Serialize the request, including the request parameters.

Source§

impl<Params> Request<&Params>
where Params: ToOwned, Params::Owned: RpcParam,

Source

pub fn into_owned_params(self) -> Request<Params::Owned>

Clone the request, including the request parameters.

Source§

impl<'a, Params> Request<Params>
where Params: AsRef<RawValue> + 'a,

Source

pub fn try_params_as<T: DeserializeOwned>(&self) -> Result<T>

Attempt to deserialize the params.

To borrow from the params via the deserializer, use Request::try_borrow_params_as.

§Returns
  • Ok(T) if the params can be deserialized as T
  • Err(e) if the params cannot be deserialized as T
Source

pub fn try_borrow_params_as<T: Deserialize<'a>>(&'a self) -> Result<T>

Attempt to deserialize the params, borrowing from the params

§Returns
  • Ok(T) if the params can be deserialized as T
  • Err(e) if the params cannot be deserialized as T

Trait Implementations§

Source§

impl<Params: Clone> Clone for Request<Params>

Source§

fn clone(&self) -> Request<Params>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Params: Debug> Debug for Request<Params>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, Params> Deserialize<'de> for Request<Params>
where Params: RpcObject,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Params: PartialEq> PartialEq for Request<Params>

Source§

fn eq(&self, other: &Request<Params>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Params> Serialize for Request<Params>
where Params: RpcParam,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Params> TryFrom<Request<Params>> for SerializedRequest
where Params: RpcParam,

Source§

type Error = Error

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

fn try_from(value: Request<Params>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<Params: Eq> Eq for Request<Params>

Source§

impl<Params> StructuralPartialEq for Request<Params>

Auto Trait Implementations§

§

impl<Params> Freeze for Request<Params>
where Params: Freeze,

§

impl<Params> RefUnwindSafe for Request<Params>
where Params: RefUnwindSafe,

§

impl<Params> Send for Request<Params>
where Params: Send,

§

impl<Params> Sync for Request<Params>
where Params: Sync,

§

impl<Params> Unpin for Request<Params>
where Params: Unpin,

§

impl<Params> UnwindSafe for Request<Params>
where Params: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

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.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> RpcObject for T
where T: RpcParam + RpcReturn,

Source§

impl<T> RpcParam for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcReturn for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,