pub struct BodyWriter<'a>(/* private fields */);Expand description
Writer for constructing the HTTP response body. Used in body_with.
§Examples
With WriteBuffer:
use maker_web::StatusCode;
resp.status(StatusCode::Ok)
.body_with(|w| {
w.write("This goes in the response body");
w.write("<html>...</html>");
w.write(true);
})With std::io::Write:
use maker_web::StatusCode;
use std::io::Write;
resp.status(StatusCode::Ok)
.body_with(|w| {
write!(w, "This goes in the response body");
write!(w, "{} - {} = {}", 6, 2, 4);
})Implementations§
Source§impl BodyWriter<'_>
impl BodyWriter<'_>
Sourcepub fn write<T: WriteBuffer>(&mut self, value: T)
pub fn write<T: WriteBuffer>(&mut self, value: T)
Appends content to the response body.
Adds data to the body section of the HTTP response. This method only affects the response body, not headers or status.
§Examples
use maker_web::StatusCode;
resp.status(StatusCode::Ok)
.body_with(|w| {
w.write("Hello");
w.write(123);
w.write(true);
})Trait Implementations§
Source§impl<'a> Debug for BodyWriter<'a>
impl<'a> Debug for BodyWriter<'a>
Source§impl Write for BodyWriter<'_>
impl Write for BodyWriter<'_>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl<'a> Freeze for BodyWriter<'a>
impl<'a> RefUnwindSafe for BodyWriter<'a>
impl<'a> Send for BodyWriter<'a>
impl<'a> Sync for BodyWriter<'a>
impl<'a> Unpin for BodyWriter<'a>
impl<'a> !UnwindSafe for BodyWriter<'a>
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