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>
impl<'a> RequestLine<'a>
Sourcepub fn parse(buffer: &'a [u8]) -> Result<Self, ParseError>
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.
Sourcepub fn parse_with_len(buffer: &'a [u8]) -> Result<(Self, usize), ParseError>
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.
Sourcepub fn path(&self) -> &'a str
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.
Sourcepub fn query(&self) -> Option<&'a str>
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").
Sourcepub fn uri(&self) -> &'a str
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.
Trait Implementations§
Source§impl<'a> Clone for RequestLine<'a>
impl<'a> Clone for RequestLine<'a>
Source§fn clone(&self) -> RequestLine<'a>
fn clone(&self) -> RequestLine<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more