[][src]Struct jrpc::Request

pub struct Request<M, T> {
    pub jsonrpc: V2_0,
    pub method: M,
    pub params: Option<T>,
    pub id: IdReq,
}

A rpc call is represented by sending a Request object to a Server.

See the parameters for details.

Examples

extern crate serde_json;
use jrpc::{Id, Request, V2_0};

let value: Vec<u32> = vec![1, 2, 3];
let request = Request::with_params(
    Id::from(4),
    "CreateFoo".to_string(),
    Some(value.clone()),
);
let json = r#"
{
    "jsonrpc": "2.0",
    "method": "CreateFoo",
    "params": [1,2,3],
    "id": 4
}
"#;
let json = json.replace("\n", "").replace(" ", "");
let result = serde_json::to_string(&request).unwrap();
assert_eq!(json, result);

Fields

jsonrpc: V2_0

A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

method: M

A serializable method.

The spec states it must be a String containing the name of the method to be invoked. This library makes no guarantees about this. It is recomended to use a simple enum for your library's method.

Section 8: Extensions

Method names that begin with "rpc." are reserved for system extensions, and MUST NOT be used for anything else. Each system extension is defined in a related specification. All system extensions are OPTIONAL.

This library provides no way of checking for system extensions.

params: Option<T>

A Structured value that holds the parameter values to be used during the invocation of the method.

Spec Requiement

Note: the following spec is not upheld by this library.

If present, parameters for the rpc call MUST be provided as a Structured value. Either by-position through an Array or by-name through an Object.

  • by-position: params MUST be an Array, containing the values in the Server expected order.
  • by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.
id: IdReq

The id. See Id

Methods

impl<M: Serialize + DeserializeOwned, T: Serialize + DeserializeOwned> Request<M, T>[src]

pub fn to_string(&self) -> String[src]

Helper to serialize the Request as json.

pub fn from_str(s: &str) -> Result<T>[src]

Helper to deserialize the Request from json.

impl<M: Serialize + DeserializeOwned> Request<M, ()>[src]

pub fn new<I>(id: I, method: M) -> Self where
    I: Into<IdReq>, 
[src]

Create a new Request.

Examples

extern crate jrpc;

extern crate serde_json;
use jrpc::{Id, Request};

let value: Vec<u32> = vec![1, 2, 3];
let request = Request::new(
    Id::from(4),
    "CreateFoo".to_string(),
);
println!("{}", request.to_string());

impl<M: Serialize + DeserializeOwned, T: Serialize + DeserializeOwned> Request<M, T>[src]

pub fn with_params<I>(id: I, method: M, params: T) -> Self where
    I: Into<IdReq>, 
[src]

Create a new Request with the specified params.

Trait Implementations

impl<M: Debug, T: Debug> Debug for Request<M, T>[src]

impl<M, T> Serialize for Request<M, T> where
    M: Serialize,
    T: Serialize
[src]

impl<'de, M, T> Deserialize<'de> for Request<M, T> where
    M: Deserialize<'de>,
    T: Deserialize<'de>,
    T: Default
[src]

Auto Trait Implementations

impl<M, T> Send for Request<M, T> where
    M: Send,
    T: Send

impl<M, T> Sync for Request<M, T> where
    M: Sync,
    T: Sync

impl<M, T> Unpin for Request<M, T> where
    M: Unpin,
    T: Unpin

impl<M, T> UnwindSafe for Request<M, T> where
    M: UnwindSafe,
    T: UnwindSafe

impl<M, T> RefUnwindSafe for Request<M, T> where
    M: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]