Skip to main content

RequestLine

Struct RequestLine 

Source
pub struct RequestLine<'a> { /* private fields */ }
Expand description

A zero-copy view of an HTTP request line.

This type borrows from the original buffer and performs no allocations. It provides access to the parsed method, path, query string, and HTTP version.

§Zero-Allocation Guarantee

All methods return borrowed data (&str or Method). No heap allocations are performed during parsing or access.

§Example

let buffer = b"GET /items/123?q=test HTTP/1.1\r\n";
let line = RequestLine::parse(buffer)?;

assert_eq!(line.method(), Method::Get);
assert_eq!(line.path(), "/items/123");
assert_eq!(line.query(), Some("q=test"));
assert_eq!(line.version(), "HTTP/1.1");

Implementations§

Source§

impl<'a> RequestLine<'a>

Source

pub fn parse(buffer: &'a [u8]) -> Result<Self, ParseError>

Parse a request line from bytes.

The buffer should contain just the request line, ending with \r\n or EOF. Example: GET /path?query HTTP/1.1\r\n

§Errors

Returns ParseError::InvalidRequestLine if the format is invalid. Returns ParseError::InvalidMethod if the HTTP method is not recognized.

Source

pub fn parse_with_len(buffer: &'a [u8]) -> Result<(Self, usize), ParseError>

Parse a request line from a buffer, returning bytes consumed.

This is useful for incremental parsing where you need to know how much of the buffer was consumed.

§Returns

Returns (RequestLine, bytes_consumed) on success. bytes_consumed includes the trailing \r\n if present.

Source

pub fn method(&self) -> Method

Returns the HTTP method.

Source

pub fn path(&self) -> &'a str

Returns the request path (without query string).

Example: For GET /items/123?q=test HTTP/1.1, returns /items/123.

Source

pub fn query(&self) -> Option<&'a str>

Returns the query string (without the leading ?), if present.

Example: For GET /items?q=test HTTP/1.1, returns Some("q=test").

Source

pub fn uri(&self) -> &'a str

Returns the full URI (path + query string).

Example: For GET /items?q=test HTTP/1.1, returns /items?q=test.

Source

pub fn version(&self) -> &'a str

Returns the HTTP version string.

Example: For GET /path HTTP/1.1, returns HTTP/1.1.

Source

pub fn is_http11(&self) -> bool

Returns true if this is HTTP/1.1.

Source

pub fn is_http10(&self) -> bool

Returns true if this is HTTP/1.0.

Trait Implementations§

Source§

impl<'a> Clone for RequestLine<'a>

Source§

fn clone(&self) -> RequestLine<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for RequestLine<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for RequestLine<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RequestLine<'a>

§

impl<'a> RefUnwindSafe for RequestLine<'a>

§

impl<'a> Send for RequestLine<'a>

§

impl<'a> Sync for RequestLine<'a>

§

impl<'a> Unpin for RequestLine<'a>

§

impl<'a> UnwindSafe for RequestLine<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ResponseProduces<T> for T