Skip to main content

Writer

Struct Writer 

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

Source

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");
Source

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)));
Source

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");
Source

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>

§

impl<'s, S> Send for Writer<'s, S>
where &'s mut S: Send,

§

impl<'s, S> Sync for Writer<'s, S>
where &'s mut S: Sync,

§

impl<'s, S> Unpin for Writer<'s, S>

§

impl<'s, S> UnsafeUnpin for Writer<'s, S>

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.