pub trait ResponseCode {
type ErrorCode: Serialize;
type BusinessCode: Serialize;
const OK: Self;
const BAD_REQUEST: Self;
const INTERNAL_SERVER_ERROR: Self;
// Required methods
fn status_code(&self) -> u16;
fn is_success(&self) -> bool;
// Provided methods
fn error_code(&self) -> Option<Self::ErrorCode> { ... }
fn business_code(&self) -> Option<Self::BusinessCode> { ... }
fn type_uri(&self) -> Option<SharedString> { ... }
fn title(&self) -> Option<SharedString> { ... }
fn message(&self) -> Option<SharedString> { ... }
}
Expand description
Trait for response code. See Problem Details for HTTP APIs.
Required Associated Constants§
Sourceconst BAD_REQUEST: Self
const BAD_REQUEST: Self
400 Bad Request.
Sourceconst INTERNAL_SERVER_ERROR: Self
const INTERNAL_SERVER_ERROR: Self
500 Internal Server Error.
Required Associated Types§
Sourcetype BusinessCode: Serialize
type BusinessCode: Serialize
A type for the business code.
Required Methods§
Sourcefn status_code(&self) -> u16
fn status_code(&self) -> u16
Status code.
Sourcefn is_success(&self) -> bool
fn is_success(&self) -> bool
Returns true
if the response is successful.
Provided Methods§
Sourcefn error_code(&self) -> Option<Self::ErrorCode>
fn error_code(&self) -> Option<Self::ErrorCode>
Error code.
Sourcefn business_code(&self) -> Option<Self::BusinessCode>
fn business_code(&self) -> Option<Self::BusinessCode>
Business code.
Sourcefn type_uri(&self) -> Option<SharedString>
fn type_uri(&self) -> Option<SharedString>
A URI reference that identifies the problem type.
For successful response, it should be None
.
Sourcefn title(&self) -> Option<SharedString>
fn title(&self) -> Option<SharedString>
A short, human-readable summary of the problem type.
For successful response, it should be None
.
Sourcefn message(&self) -> Option<SharedString>
fn message(&self) -> Option<SharedString>
A context-specific descriptive message. If the response is not successful, it should be a human-readable explanation specific to this occurrence of the problem.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.