pub struct Output<'a> { /* private fields */ }Expand description
Where an engine writes: the reply body, reused between requests, with a size budget.
use web_net::Output;
let mut buf = Vec::new();
let mut out = Output::new(&mut buf, 64);
out.write_str("<p>hi</p>")?;
assert_eq!(out.remaining(), 55);
assert_eq!(buf, b"<p>hi</p>");Implementations§
Source§impl<'a> Output<'a>
impl<'a> Output<'a>
Sourcepub fn new(buf: &'a mut Vec<u8>, limit: usize) -> Self
pub fn new(buf: &'a mut Vec<u8>, limit: usize) -> Self
An output over buf, refusing to grow past limit bytes.
use web_net::Output;
let mut buf = Vec::new();
let mut out = Output::new(&mut buf, 4);
assert!(out.write(b"1234").is_ok());
assert_eq!(out.write(b"5").unwrap_err().code(), "render.too_large");Sourcepub fn write(&mut self, bytes: &[u8]) -> Result<(), RenderError>
pub fn write(&mut self, bytes: &[u8]) -> Result<(), RenderError>
Appends bytes.
use web_net::Output;
let mut buf = Vec::new();
let mut out = Output::new(&mut buf, 64);
out.write(b"<p>")?;
assert_eq!(out.len(), 3);§Errors
render.too_large when the page would pass the budget.
Sourcepub fn buffer(&mut self) -> &mut Vec<u8> ⓘ
pub fn buffer(&mut self) -> &mut Vec<u8> ⓘ
The buffer itself, for an engine that writes into a Vec<u8>. The
budget is checked when the engine returns: a page past it is refused
with render.too_large.
use std::io::Write;
use web_net::Output;
let mut buf = Vec::new();
let mut out = Output::new(&mut buf, 64);
write!(out.buffer(), "{} items", 3).unwrap();
assert_eq!(out.len(), 7);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Bytes written so far.
use web_net::Output;
let mut buf = Vec::new();
let mut out = Output::new(&mut buf, 64);
out.write_str("hello")?;
assert_eq!(out.len(), 5);Trait Implementations§
Auto Trait Implementations§
impl<'a> !UnwindSafe for Output<'a>
impl<'a> Forget for Output<'a>
impl<'a> Freeze for Output<'a>
impl<'a> Move for Output<'a>
impl<'a> RefUnwindSafe for Output<'a>
impl<'a> Send for Output<'a>
impl<'a> Sync for Output<'a>
impl<'a> Unpin for Output<'a>
impl<'a> UnsafeUnpin for Output<'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