pub struct Span {
pub start: u32,
pub end: u32,
}Expand description
A byte range of a message head: start..end, as offsets into
RawHead::bytes (or into the input of a
stateless parser).
Offsets are u32 because every budget in Limits is capped at
16 MiB, so a head can never be longer. Spans stay valid when the head
bytes are moved or copied, which is what makes a head cheap to copy into
a passport (RequestHead::copy_into).
§Examples
use http_net::Span;
let head = b"GET / HTTP/1.1\r\n";
let method = Span { start: 0, end: 3 };
assert_eq!(method.get(head), b"GET");
assert_eq!(method.len(), 3);
// Out of range: an empty slice, never a panic.
assert_eq!(Span { start: 10, end: 99 }.get(head), b"");Fields§
§start: u32The first byte.
end: u32One past the last byte.
Implementations§
Source§impl Span
impl Span
Sourcepub fn get<'b>(&self, head: &'b [u8]) -> &'b [u8] ⓘ
pub fn get<'b>(&self, head: &'b [u8]) -> &'b [u8] ⓘ
The bytes of head the span covers; empty when the span lies
outside head or is reversed.
§Examples
let span = http_net::Span { start: 4, end: 5 };
assert_eq!(span.get(b"GET / HTTP/1.1"), b"/");Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
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