pub struct Response {
pub status: Status,
pub code: u16,
pub message: String,
pub payload: Option<Value>,
pub payload_kind: Option<PayloadKind>,
pub error: Option<ErrorDetail>,
}Fields§
§status: Status§code: u16§message: String§payload: Option<Value>§payload_kind: Option<PayloadKind>§error: Option<ErrorDetail>Implementations§
Source§impl Response
impl Response
pub fn success(code: u16, message: impl Into<String>) -> Self
pub fn success_with_payload( code: u16, message: impl Into<String>, payload: Value, ) -> Self
Sourcepub fn success_typed(
code: u16,
message: impl Into<String>,
kind: PayloadKind,
payload: Value,
) -> Self
pub fn success_typed( code: u16, message: impl Into<String>, kind: PayloadKind, payload: Value, ) -> Self
Create a success response with typed payload for reliable formatter matching.
Use this instead of success_with_payload when you know the exact payload type.
Sourcepub fn err(code: u16, message: impl Into<String>, kind: ErrorKind) -> Self
pub fn err(code: u16, message: impl Into<String>, kind: ErrorKind) -> Self
Create an error response with ErrorKind
Sourcepub fn err_with_details(
code: u16,
message: impl Into<String>,
kind: ErrorKind,
details: impl Into<String>,
) -> Self
pub fn err_with_details( code: u16, message: impl Into<String>, kind: ErrorKind, details: impl Into<String>, ) -> Self
Create an error response with ErrorKind and details
Sourcepub fn from_http_error(err: &HttpError, context: &str) -> Self
pub fn from_http_error(err: &HttpError, context: &str) -> Self
Create a Response from an HttpError, preserving the original status code
pub fn to_json(&self) -> String
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 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