pub struct AppResponse {
pub code: i32,
pub data: Value,
pub message: String,
pub meta: Meta,
}Expand description
Standardized app-level response placed in JSON-RPC result.
Implements AppResponseView / AppResponseMut so application crates can wrap
or override helpers Public fields are for serde and call-site convenience.
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!(1));
assert_eq!(r.code, 200);
assert_eq!(r.data, json!(1));Fields§
§code: i32HTTP-style status code (200 success, 400/404/… for app errors).
data: ValueBusiness payload (null on error envelopes).
message: StringHuman message (msg in JSON).
meta: MetaOptional metadata (endpoint name, close hint).
Implementations§
Source§impl AppResponse
impl AppResponse
Sourcepub fn ok(data: Value) -> Self
pub fn ok(data: Value) -> Self
Build a success envelope (code = 200, msg = "OK").
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!("pong"));
assert_eq!(r.code, 200);
assert_eq!(r.data, json!("pong"));Sourcepub fn error(code: i32, message: impl Into<String>) -> Self
pub fn error(code: i32, message: impl Into<String>) -> Self
Build an error envelope (data is always JSON null).
§Examples
use simplejrpc::AppResponse;
let r = AppResponse::error(404, "Not Found");
assert_eq!(r.code, 404);
assert!(r.data.is_null());Sourcepub fn from_parts(code: i32, data: Value, message: String, meta: Meta) -> Self
pub fn from_parts(code: i32, data: Value, message: String, meta: Meta) -> Self
Build from raw parts.
§Examples
use simplejrpc::response::{AppResponse, Meta};
use serde_json::json;
let r = AppResponse::from_parts(200, json!(1), "OK".into(), Meta::default());
assert!(r.is_ok());Sourcepub fn into_parts(self) -> (i32, Value, String, Meta)
pub fn into_parts(self) -> (i32, Value, String, Meta)
Split into raw parts (pair with Self::from_parts).
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let (code, data, msg, meta) = AppResponse::ok(json!(1)).into_parts();
assert_eq!(code, 200);
assert_eq!(data, json!(1));
assert_eq!(msg, "OK");
assert_eq!(meta.close, 0);Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Whether Self::code is 200.
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
assert!(AppResponse::ok(json!(null)).is_ok());
assert!(!AppResponse::error(400, "x").is_ok());Sourcepub fn with_endpoint(self, endpoint: impl Into<String>) -> Self
pub fn with_endpoint(self, endpoint: impl Into<String>) -> Self
Set Meta::endpoint (fluent).
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!(null)).with_endpoint("add");
assert_eq!(r.meta.endpoint, "add");Sourcepub fn with_close(self, close: i32) -> Self
pub fn with_close(self, close: i32) -> Self
Set Meta::close (fluent).
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!(null)).with_close(1);
assert_eq!(r.meta.close, 1);Sourcepub fn with_data(self, data: Value) -> Self
pub fn with_data(self, data: Value) -> Self
Replace Self::data (fluent).
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!(null)).with_data(json!([1, 2]));
assert_eq!(r.data, json!([1, 2]));Sourcepub fn with_message(self, message: impl Into<String>) -> Self
pub fn with_message(self, message: impl Into<String>) -> Self
Replace Self::message (fluent).
§Examples
use simplejrpc::AppResponse;
use serde_json::json;
let r = AppResponse::ok(json!(null)).with_message("done");
assert_eq!(r.message, "done");Trait Implementations§
Source§impl AppResponseMut for AppResponse
impl AppResponseMut for AppResponse
Source§fn set_message(&mut self, message: impl Into<String>)
fn set_message(&mut self, message: impl Into<String>)
Replace the human message (
msg).Source§fn with_endpoint(self, endpoint: impl Into<String>) -> Selfwhere
Self: Sized,
fn with_endpoint(self, endpoint: impl Into<String>) -> Selfwhere
Self: Sized,
Set
Meta::endpoint (fluent, consumes self).Source§fn with_close(self, close: i32) -> Selfwhere
Self: Sized,
fn with_close(self, close: i32) -> Selfwhere
Self: Sized,
Set
Meta::close (fluent, consumes self).Source§impl AppResponseView for AppResponse
impl AppResponseView for AppResponse
Source§fn to_app_response(&self) -> AppResponse
fn to_app_response(&self) -> AppResponse
Build an
AppResponse from the view getters.Source§impl Clone for AppResponse
impl Clone for AppResponse
Source§impl Debug for AppResponse
impl Debug for AppResponse
Source§impl Default for AppResponse
impl Default for AppResponse
Source§impl<'de> Deserialize<'de> for AppResponse
impl<'de> Deserialize<'de> for AppResponse
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for AppResponse
impl PartialEq for AppResponse
Source§impl Serialize for AppResponse
impl Serialize for AppResponse
impl StructuralPartialEq for AppResponse
Auto Trait Implementations§
impl Freeze for AppResponse
impl RefUnwindSafe for AppResponse
impl Send for AppResponse
impl Sync for AppResponse
impl Unpin for AppResponse
impl UnsafeUnpin for AppResponse
impl UnwindSafe for AppResponse
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