ResponseBuilder

Struct ResponseBuilder 

Source
pub struct ResponseBuilder;
Expand description

HTTP response builder (suitable for plugin runtime).

Provides the following construction capabilities:

  • Success response (JSON).
  • Error response (automatic mapping of status codes and structures).
  • File stream response (opens files based on host UUID).
  • Status code response (pure status code, no body).

Implementations§

Source§

impl ResponseBuilder

Source

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

Constructs a JSON response (200 OK).

鈿狅笍 If serialization fails, [] is returned as fallback content; this does not indicate logic success.

Source

pub fn error(err: VtxError) -> Response

Constructs an error response (automatically maps HTTP status codes based on error type).

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

Return structure:

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

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

Constructs a file stream response (opens via host interface by UUID).

  • Success: 200 + file content stream.
  • Failure: Returns 404 JSON error response.
Source

pub fn status(code: u16) -> Response

Constructs a pure status code response (no body).

Used for scenarios such as 204 No Content, 403 Forbidden, etc.

Source

pub fn not_found() -> Response

Constructs a standard 404 Not Found response (no body).

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.