pub struct Response {
pub msg_type: String,
pub id: String,
pub status: ResponseStatus,
pub result: Option<Value>,
pub error: Option<ResponseError>,
pub meta: ResponseMeta,
}Expand description
Response message envelope.
Fields§
§msg_type: StringMessage type, always “response”.
id: StringRequest ID this response correlates to.
status: ResponseStatusResponse status.
result: Option<Value>Result payload (for successful responses).
error: Option<ResponseError>Error details (for error responses).
meta: ResponseMetaResponse metadata.
Implementations§
Source§impl Response
impl Response
Sourcepub fn ok(id: impl Into<String>, result: Value) -> Self
pub fn ok(id: impl Into<String>, result: Value) -> Self
Creates a successful response.
§Examples
use rstmdb_protocol::{Response, ResponseError};
use rstmdb_protocol::ErrorCode;
use serde_json::json;
let ok = Response::ok("1", json!({"pong": true}));
assert!(ok.is_ok());
let err = Response::error("2", ResponseError::new(
ErrorCode::NotFound, "not found",
));
assert!(err.is_error());pub fn error(id: impl Into<String>, error: ResponseError) -> Self
pub fn with_meta(self, meta: ResponseMeta) -> Self
pub fn is_ok(&self) -> bool
pub fn is_error(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
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
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
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