Skip to main content

write_content_range

Function write_content_range 

Source
pub fn write_content_range(
    r: ByteRange,
    complete: Option<u64>,
    out: &mut impl Sink,
) -> Result<(), WriteError>
Expand description

Writes bytes first-last/complete, or bytes first-last/* when the complete length is unknown.

§Errors

WriteError::OutOfRange when end < start or end >= complete; WriteError::Full (nothing written when the sink reports its room).

§Examples

use parse_net::{range::write_content_range, ByteRange, SliceSink, WriteError};

let mut buf = [0u8; 32];
let mut out = SliceSink::new(&mut buf);
write_content_range(ByteRange { start: 0, end: 9 }, None, &mut out)?;
assert_eq!(out.written(), b"bytes 0-9/*");
assert_eq!(write_content_range(ByteRange { start: 0, end: 9 }, Some(5), &mut out), Err(WriteError::OutOfRange));