Struct synchronous_server::http::status::Status
source · pub struct Status {
pub text: String,
pub code: u16,
}Expand description
HTTP status
Fields§
§text: String§code: u16Implementations§
source§impl Status
impl Status
sourcepub fn new(code: u16) -> Status
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(())
}sourcepub fn to_full_string(&self) -> String
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(())
}pub fn to_string(&self) -> String
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Status
impl Send for Status
impl Sync for Status
impl Unpin for Status
impl UnwindSafe for Status
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