pub struct Writer<'s, S: Sink> { /* private fields */ }Expand description
Writes Cache-Control directives, separated by , .
Delta-seconds are always written as tokens (senders must not quote them); field lists are always quoted.
§Examples
use parse_net::{cache::Writer, SliceSink};
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
Writer::new(&mut out).flag("no-store")?.seconds("max-age", 0)?;
assert_eq!(out.written(), b"no-store, max-age=0");Implementations§
Source§impl<'s, S: Sink> Writer<'s, S>
impl<'s, S: Sink> Writer<'s, S>
Sourcepub fn new(out: &'s mut S) -> Self
pub fn new(out: &'s mut S) -> Self
A writer over out.
§Examples
use parse_net::{cache::Writer, SliceSink};
let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
let mut w = Writer::new(&mut out);
w.flag("public")?;
assert_eq!(out.written(), b"public");Sourcepub fn flag(&mut self, name: &str) -> Result<&mut Self, WriteError>
pub fn flag(&mut self, name: &str) -> Result<&mut Self, WriteError>
Writes a directive with no argument (no-store).
§Errors
WriteError::NotToken; WriteError::Full (nothing written for
this directive when the sink reports its room).
§Examples
use parse_net::{cache::Writer, SliceSink, WriteError};
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
Writer::new(&mut out).flag("no-store")?.flag("no-transform")?;
assert_eq!(out.written(), b"no-store, no-transform");
assert!(matches!(Writer::new(&mut out).flag("no store"), Err(WriteError::NotToken)));Sourcepub fn seconds(
&mut self,
name: &str,
secs: u32,
) -> Result<&mut Self, WriteError>
pub fn seconds( &mut self, name: &str, secs: u32, ) -> Result<&mut Self, WriteError>
Writes name=secs (max-age=60).
§Errors
As flag.
§Examples
use parse_net::{cache::Writer, SliceSink};
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
Writer::new(&mut out).seconds("max-age", 3600)?.seconds("stale-while-revalidate", 30)?;
assert_eq!(out.written(), b"max-age=3600, stale-while-revalidate=30");Sourcepub fn fields(
&mut self,
name: &str,
fields: &[&str],
) -> Result<&mut Self, WriteError>
pub fn fields( &mut self, name: &str, fields: &[&str], ) -> Result<&mut Self, WriteError>
Writes name="field, field" (no-cache="Set-Cookie").
§Errors
WriteError::NotToken for the name or a field name, and as
flag.
§Examples
use parse_net::{cache::Writer, SliceSink};
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
Writer::new(&mut out).fields("no-cache", &["Set-Cookie", "Authorization"]).expect("room");
assert_eq!(out.written(), b"no-cache=\"Set-Cookie, Authorization\"");Auto Trait Implementations§
impl<'s, S> !UnwindSafe for Writer<'s, S>
impl<'s, S> Freeze for Writer<'s, S>
impl<'s, S> RefUnwindSafe for Writer<'s, S>where
&'s mut S: RefUnwindSafe,
impl<'s, S> Send for Writer<'s, S>
impl<'s, S> Sync for Writer<'s, S>
impl<'s, S> Unpin for Writer<'s, S>
impl<'s, S> UnsafeUnpin for Writer<'s, S>where
&'s mut S: UnsafeUnpin,
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