pub struct TransferCodings { /* private fields */ }Expand description
A collection of transfer codings with validation according to HTTP standards.
This struct ensures that:
- “chunked” appears at most once
- “chunked” is always the last transfer coding
Implementations§
Source§impl TransferCodings
impl TransferCodings
Sourcepub fn new() -> TransferCodings
pub fn new() -> TransferCodings
Sourcepub fn push(&mut self, coding: TransferCoding) -> Result<(), &'static str>
pub fn push(&mut self, coding: TransferCoding) -> Result<(), &'static str>
Adds a transfer coding to the collection, with validation.
According to HTTP standards:
- “chunked” can appear at most once
- “chunked” must be the last transfer coding
§Arguments
coding- The transfer coding to add
§Returns
Ok(()) if the coding was successfully added, or an error message
explaining why the coding could not be added.
§Examples
use crate::encoding::{TransferCodings, TransferCoding};
let mut codings = TransferCodings::new();
// Add a non-chunked coding
codings.push(TransferCoding::Other("gzip".into())).unwrap();
// Add chunked coding (must be last)
codings.push(TransferCoding::Chunked).unwrap();
// Cannot add another coding after chunked
assert!(codings.push(TransferCoding::Other("compress".into())).is_err());
// Cannot add chunked twice
let mut codings = TransferCodings::new();
codings.push(TransferCoding::Chunked).unwrap();
assert!(codings.push(TransferCoding::Chunked).is_err());Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Checks if chunked transfer encoding is used.
§Returns
true if chunked encoding is present, false otherwise
§Examples
use crate::encoding::{TransferCodings, TransferCoding};
let mut codings = TransferCodings::new();
assert!(!codings.is_chunked());
codings.push(TransferCoding::Chunked).unwrap();
assert!(codings.is_chunked());Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Checks if identity transfer encoding is used (no transfer encoding).
§Returns
true if no transfer encodings are present, false otherwise
§Examples
use crate::encoding::{TransferCodings, TransferCoding};
let mut codings = TransferCodings::new();
assert!(codings.is_identity());
codings.push(TransferCoding::Chunked).unwrap();
assert!(!codings.is_identity());Sourcepub fn to_header(&self) -> String
pub fn to_header(&self) -> String
Converts the transfer codings to a header value string.
§Returns
A comma-separated string of transfer codings
§Examples
use crate::encoding::{TransferCodings, TransferCoding};
let mut codings = TransferCodings::new();
codings.push(TransferCoding::Other("gzip".into())).unwrap();
codings.push(TransferCoding::Chunked).unwrap();
assert_eq!(codings.to_header(), "gzip, chunked");Trait Implementations§
Source§impl Clone for TransferCodings
impl Clone for TransferCodings
Source§fn clone(&self) -> TransferCodings
fn clone(&self) -> TransferCodings
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TransferCodings
impl Debug for TransferCodings
Source§impl Default for TransferCodings
impl Default for TransferCodings
Source§fn default() -> TransferCodings
fn default() -> TransferCodings
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TransferCodings
impl RefUnwindSafe for TransferCodings
impl Send for TransferCodings
impl Sync for TransferCodings
impl Unpin for TransferCodings
impl UnsafeUnpin for TransferCodings
impl UnwindSafe for TransferCodings
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> ParamValue for T
impl<T> ParamValue for T
Source§fn clone_box(&self) -> Box<dyn ParamValue>
fn clone_box(&self) -> Box<dyn ParamValue>
Clones this value and returns it as a boxed
ParamValue. Read moreSource§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Returns a reference to the underlying value as
Any. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns a mutable reference to the underlying value as
Any. Read more