pub struct Request<T> {
pub jsonrpc: Version,
pub id: Option<Id>,
pub body: T,
}Expand description
The generic T is the body type of the request, i.e. it is the
type that holds both the method and params.
Fields§
§jsonrpc: VersionJSON-RPC protocol version; always 2.0.
id: Option<Id>An identifier established by the Client.
If it is not included it is assumed to be a notification.
§None vs Some(Id::Null)
This field will be completely omitted during serialization if None,
however if it is Some(Id::Null), it will be serialized as "id": null.
Note that the JSON-RPC 2.0 specification discourages the use of Id::NUll,
so if there is no ID needed, consider using None.
body: TThe method and params fields.
method: A type that serializes as the name of the method to be invoked.params: A structured value that holds the parameter values to be used during the invocation of the method.
As mentioned in the library documentation, there are no method/params fields in Request,
they are both merged in this body field which is #[serde(flatten)]ed.
§Invariant
Your T must serialize as method and params to comply with the specification.
Implementations§
Source§impl<T> Request<T>
impl<T> Request<T>
Sourcepub const fn new_with_id(id: Id, body: T) -> Self
pub const fn new_with_id(id: Id, body: T) -> Self
Sourcepub const fn is_notification(&self) -> bool
pub const fn is_notification(&self) -> bool
Returns true if the request is notification.
In other words, if id is None, this returns true.
use cuprate_json_rpc::{Id, Request};
assert!(Request::new("").is_notification());
assert!(!Request::new_with_id(Id::Null, "").is_notification());Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Request<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Request<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Ord> Ord for Request<T>
impl<T: Ord> Ord for Request<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd> PartialOrd for Request<T>
impl<T: PartialOrd> PartialOrd for Request<T>
impl<T: Eq> Eq for Request<T>
impl<T> StructuralPartialEq for Request<T>
Auto Trait Implementations§
impl<T> Freeze for Request<T>where
T: Freeze,
impl<T> RefUnwindSafe for Request<T>where
T: RefUnwindSafe,
impl<T> Send for Request<T>where
T: Send,
impl<T> Sync for Request<T>where
T: Sync,
impl<T> Unpin for Request<T>where
T: Unpin,
impl<T> UnwindSafe for Request<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.