Trait for types that can be converted into JSON-RPC request objects. Implementing this trait allows a struct to be used as a typed JSON-RPC request, with an associated method name and automatic conversion to the request format.
| 16 | /// request, with an associated method name and automatic conversion to the |
| 17 | /// request format. |
| 18 | pub trait JsonRpcRequest: Serialize { |
| 19 | const METHOD: &'static str; |
| 20 | fn into_request(self) -> RequestObject<Self> |
| 21 | where |
| 22 | Self: Sized, |
| 23 | { |
| 24 | Self::into_request_with_id(self, Some(generate_random_id())) |
| 25 | } |
| 26 | |
| 27 | fn into_request_with_id(self, id: Option<String>) -> RequestObject<Self> |
| 28 | where |
| 29 | Self: Sized, |
| 30 | { |
| 31 | RequestObject { |
| 32 | jsonrpc: "2.0".into(), |
| 33 | method: Self::METHOD.into(), |
| 34 | params: Some(self), |
| 35 | id, |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /// Generates a random ID for JSON-RPC requests. |
| 41 | /// |
no outgoing calls
no test coverage detected