Enum jrpc::Response
[−]
[src]
pub enum Response<T> { Ok(Success<T>), Err(Error<Value>), }
The Result is either:
- a jsonrpc Response (with a result of a specific type)
- a Error (with an error of type
serde_json::Value
).
Example
extern crate serde_json; use jrpc::{Id, Response}; let data: Vec<u32> = vec![1, 2, 3]; let example = Response::success(Id::from(4), data.clone()); let json = r#" { "jsonrpc": "2.0", "result": [1,2,3], "id": 4 } "#; let json = json.replace("\n", "").replace(" ", ""); let result = serde_json::to_string(&example).unwrap(); assert_eq!(json, result);
Variants
Ok(Success<T>)
The Response has a result
object and not an error
object.
Err(Error<Value>)
The Response has a error
object and not an result
object.
Methods
impl<T: Serialize + DeserializeOwned> Response<T>
[src]
pub fn id(&self) -> &Id
[src]
Retrieve the id
regardless of whether there was an error or not.
pub fn success(id: Id, result: T) -> Self
[src]
Construct a Success
pub fn error<C, S>(id: Id, code: C, message: S, data: Option<Value>) -> Self where
C: Into<ErrorCode>,
S: Into<String>,
[src]
C: Into<ErrorCode>,
S: Into<String>,
Construct an Error
pub fn to_string(&self) -> String
[src]
Helper to serialize the Response as json.
pub fn from_str(s: &str) -> Result<T>
[src]
Helper to deserialize the Response from json.