pub struct CanonicalResponse {
pub status_code: u16,
/* private fields */
}Expand description
统一规范化响应
所有HTTP协议处理后的统一响应结构。
§设计特点
- 零堆分配:小 Body 使用栈上固定数组,超过 MAX_BODY_LEN 时才使用堆
- Copy 语义:仅当 Body 超过栈容量时放弃 Copy
Fields§
§status_code: u16状态码
Implementations§
Source§impl CanonicalResponse
impl CanonicalResponse
Sourcepub const fn new(status_code: u16) -> CanonicalResponse
pub const fn new(status_code: u16) -> CanonicalResponse
创建响应(零堆分配)
Sourcepub const fn ok() -> CanonicalResponse
pub const fn ok() -> CanonicalResponse
创建简单的成功响应
Sourcepub const fn error(status_code: u16) -> CanonicalResponse
pub const fn error(status_code: u16) -> CanonicalResponse
创建简单的错误响应
Sourcepub fn header_count(&self) -> u8
pub fn header_count(&self) -> u8
获取头部数量
Sourcepub fn headers_iter(&self) -> &[CanonicalHeader]
pub fn headers_iter(&self) -> &[CanonicalHeader]
获取头部迭代器
Sourcepub fn find_header(&self, name: &str) -> Option<&CanonicalHeader>
pub fn find_header(&self, name: &str) -> Option<&CanonicalHeader>
按名称查找头部(ASCII 大小写不敏感,RFC 7230 §3.2)
Trait Implementations§
Source§impl Clone for CanonicalResponse
impl Clone for CanonicalResponse
Source§fn clone(&self) -> CanonicalResponse
fn clone(&self) -> CanonicalResponse
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CanonicalResponse
impl Debug for CanonicalResponse
Source§impl Default for CanonicalResponse
impl Default for CanonicalResponse
Source§fn default() -> CanonicalResponse
fn default() -> CanonicalResponse
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CanonicalResponse
impl RefUnwindSafe for CanonicalResponse
impl Send for CanonicalResponse
impl Sync for CanonicalResponse
impl Unpin for CanonicalResponse
impl UnsafeUnpin for CanonicalResponse
impl UnwindSafe for CanonicalResponse
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