pub struct Status {
    pub text: String,
    pub code: u16,
}
Expand description

HTTP status

Fields§

§text: String§code: u16

Implementations§

source§

impl Status

source

pub fn new(code: u16) -> Status

Create HTTP status from code

Examples found in repository?
examples/hello-world.rs (line 16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub fn main() -> Result<()> {
    let res = listen("0.0.0.0:4001", |d| {
        println!("{:?}", d);

        let result = "hello world".to_string();
        let code = 200;
        let headers = Headers::new_request(
            Status::new(code).to_full_string().as_str(),
            vec![
                Header {
                    name: "Content-Type".to_string(),
                    value: "text/plain".to_string(),
                },
                Header {
                    name: "Custom-Header".to_string(),
                    value: "Hello World!".to_string(),
                },
            ],
        );

        Ok((result, code, headers))
    });
    if let Err(err) = res {
        println!("Failed to listen server: {:?}", err);
    }

    Ok(())
}
source

pub fn to_full_string(&self) -> String

Get HTTP protocol prefix like HTTP/1.1 200 OK

Examples found in repository?
examples/hello-world.rs (line 16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub fn main() -> Result<()> {
    let res = listen("0.0.0.0:4001", |d| {
        println!("{:?}", d);

        let result = "hello world".to_string();
        let code = 200;
        let headers = Headers::new_request(
            Status::new(code).to_full_string().as_str(),
            vec![
                Header {
                    name: "Content-Type".to_string(),
                    value: "text/plain".to_string(),
                },
                Header {
                    name: "Custom-Header".to_string(),
                    value: "Hello World!".to_string(),
                },
            ],
        );

        Ok((result, code, headers))
    });
    if let Err(err) = res {
        println!("Failed to listen server: {:?}", err);
    }

    Ok(())
}
source

pub fn to_string(&self) -> String

Trait Implementations§

source§

impl Debug for Status

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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>,

§

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>,

§

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.