pub struct JsonRpcExtractor {
pub parsed: Value,
pub method: String,
pub id: Id,
}
Expand description
Parses a JSON-RPC request, and returns the request ID, the method name, and the parameters. If the request is invalid, returns an error.
use axum_jrpc::{JrpcResult, JsonRpcExtractor, JsonRpcResponse};
fn router(req: JsonRpcExtractor) -> JrpcResult {
let req_id = req.get_answer_id();
let method = req.method();
match method {
"add" => {
let params: [i32;2] = req.parse_params()?;
return Ok(JsonRpcResponse::success(req_id, params[0] + params[1]));
}
m => Ok(req.method_not_found(m))
}
}
Fields§
§parsed: Value
§method: String
§id: Id
Implementations§
Source§impl JsonRpcExtractor
impl JsonRpcExtractor
pub fn get_answer_id(&self) -> Id
pub fn parse_params<T: DeserializeOwned>(self) -> Result<T, JsonRpcResponse>
pub fn method(&self) -> &str
pub fn method_not_found(&self, method: &str) -> JsonRpcResponse
Trait Implementations§
Source§impl Clone for JsonRpcExtractor
impl Clone for JsonRpcExtractor
Source§fn clone(&self) -> JsonRpcExtractor
fn clone(&self) -> JsonRpcExtractor
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for JsonRpcExtractor
impl Debug for JsonRpcExtractor
Source§impl<S> FromRequest<S> for JsonRpcExtractor
impl<S> FromRequest<S> for JsonRpcExtractor
Auto Trait Implementations§
impl Freeze for JsonRpcExtractor
impl RefUnwindSafe for JsonRpcExtractor
impl Send for JsonRpcExtractor
impl Sync for JsonRpcExtractor
impl Unpin for JsonRpcExtractor
impl UnwindSafe for JsonRpcExtractor
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
Mutably borrows from an owned value. Read more