ResponseBuilder

Struct ResponseBuilder 

Source
pub struct ResponseBuilder;
Expand description

HTTP 响应构造器(适用于插件运行时)

提供以下构造能力:

  • 成功响应(JSON)
  • 错误响应(自动映射状态码与结构体)
  • 文件流响应(基于宿主 UUID 打开文件)
  • 状态码响应(纯状态码,无 body)

Implementations§

Source§

impl ResponseBuilder

Source

pub fn json<T: Serialize>(data: &T) -> Response

构造 JSON 响应(200 OK)

⚠️ 若序列化失败,返回 [] 作为兜底内容,不表示逻辑成功

Source

pub fn error(err: VtxError) -> Response

构造错误响应(根据错误类型自动映射 HTTP 状态码)

  • AuthDenied(code)code(401 / 403)
  • NotFound(_) → 404
  • PermissionDenied(_) → 403
  • SerializationError(_) → 400
  • DatabaseError(_), Internal(_) → 500

返回结构:

{
  "success": false,
  "error": true,
  "code": 403,
  "type": "PermissionDenied",
  "message": "You are not allowed to access this resource"
}
Source

pub fn file(uuid: &str) -> Response

构造文件流响应(通过宿主接口按 UUID 打开)

  • 成功:200 + 文件内容流
  • 失败:返回 404 JSON 错误响应
Source

pub fn status(code: u16) -> Response

构造纯状态码响应(无 body)

用于如:204 No Content、403 Forbidden 等响应场景

Source

pub fn not_found() -> Response

构造标准 404 Not Found 响应(无正文)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.