Trait ngyn_shared::server::response::FullResponse

source ·
pub trait FullResponse {
    // Required methods
    fn set_status(&mut self, status: u16);
    fn set_header<K: IntoHeaderName>(&mut self, name: K, value: &str);
    fn send(&mut self, item: impl ToBytes);
}
Expand description

Trait representing a full response.

Required Methods§

source

fn set_status(&mut self, status: u16)

Sets the status code of the response.

§Arguments
  • status - The status code to set.
§Examples
use http_body_util::Full;
use hyper::StatusCode;
use crate::{context::NgynContext, transformer::Transformer, NgynResponse, ToBytes};

struct MyResponse {
    status: StatusCode,
}

let mut response = MyResponse { status: StatusCode::OK };
response.set_status(200);
assert_eq!(response.status, StatusCode::OK);
source

fn set_header<K: IntoHeaderName>(&mut self, name: K, value: &str)

Sets a header - name, value pair - of the response.

§Arguments
  • name - The name of the header.
  • value - The value of the header.
§Examples
let mut response = NgynResponse::default();
response.set_header("Content-Type", "application/json");
assert_eq!(response.headers.get("Content-Type"), Some(&"application/json".to_string()));
source

fn send(&mut self, item: impl ToBytes)

Sends the body of the response.

§Arguments
  • item - The item to parse the body from.
§Examples
use http_body_util::Full;
use hyper::StatusCode;
use crate::{context::NgynContext, transformer::Transformer, NgynResponse, ToBytes};

struct MyResponse {
    body: Full,
}

let mut response = MyResponse { body: Full::new(vec![1, 2, 3]) };
response.send(vec![4, 5, 6]);
assert_eq!(response.body.as_slice(), &[4, 5, 6]);

Object Safety§

This trait is not object safe.

Implementors§