Skip to main content

RequestBuilder

Struct RequestBuilder 

Source
pub struct RequestBuilder<'a, P: Phase = Query> { /* private fields */ }
Expand description

Typestate request builder. Writes directly into a RequestWriter’s buffer — no intermediate storage, no stream type parameter.

Phase type parameter enforces correct wire ordering at compile time: query parameters before headers, headers before body.

Implementations§

Source§

impl<'a> RequestBuilder<'a, Query>

Source

pub fn query(self, key: &str, value: &str) -> Self

Add a query parameter. Percent-encodes key and value per RFC 3986.

Source

pub fn query_raw(self, key: &str, value: &str) -> Self

Add a pre-encoded query parameter. No percent-encoding applied.

Caller is responsible for correct encoding. Validates no CR/LF.

Source

pub fn header(self, name: &str, value: &str) -> RequestBuilder<'a, Headers>

Add a request header. Transitions to the headers phase.

Source

pub fn body(self, body: &[u8]) -> RequestBuilder<'a, Ready>

Set the request body. Transitions to the ready phase.

Source

pub fn body_writer<F, E>(self, f: F) -> RequestBuilder<'a, Ready>
where F: FnOnce(&mut BodyWriter<'_>) -> Result<(), E>, E: Into<Box<dyn Error + Send + Sync>>,

Write the body directly into the buffer via a closure.

Zero-alloc: the closure writes into the WriteBuf’s spare region via BodyWriter (implements std::io::Write). Content-Length is computed and backfilled automatically.

let req = writer.post("/order")
    .body_writer(|w| serde_json::to_writer(w, &order))
    .finish()?;
Source

pub fn body_fixed( self, len: usize, f: impl FnOnce(&mut [u8]), ) -> RequestBuilder<'a, Ready>

Write a fixed-size body via closure with direct &mut [u8] access.

The caller specifies the exact body size upfront. Content-Length is written with exact digits (no backfill). The closure receives a zeroed &mut [u8] slice of exactly len bytes to write into.

For binary wire formats (SBE, FIX, protobuf) where the message size is known at construction time.

let req = writer.post("/order")
    .body_fixed(128, |buf| {
        order.encode_sbe(buf);
    })
    .finish()?;
Source

pub fn finish(self) -> Result<Request<'a>, RestError>

Finish building. Returns the assembled request bytes.

Source§

impl<'a> RequestBuilder<'a, Headers>

Source

pub fn header(self, name: &str, value: &str) -> Self

Add a request header.

Source

pub fn body(self, body: &[u8]) -> RequestBuilder<'a, Ready>

Set the request body. Transitions to the ready phase.

Source

pub fn body_writer<F, E>(self, f: F) -> RequestBuilder<'a, Ready>
where F: FnOnce(&mut BodyWriter<'_>) -> Result<(), E>, E: Into<Box<dyn Error + Send + Sync>>,

Write the body directly into the buffer via a closure.

Same as RequestBuilder<Query>::body_writer — see its docs.

Source

pub fn body_fixed( self, len: usize, f: impl FnOnce(&mut [u8]), ) -> RequestBuilder<'a, Ready>

Write a fixed-size body via closure with direct &mut [u8] access.

Same as RequestBuilder<Query>::body_fixed — see its docs.

Source

pub fn finish(self) -> Result<Request<'a>, RestError>

Finish building. Returns the assembled request bytes.

Source§

impl<'a> RequestBuilder<'a, Ready>

Source

pub fn finish(self) -> Result<Request<'a>, RestError>

Finish building. Returns the assembled request bytes.

Auto Trait Implementations§

§

impl<'a, P> Freeze for RequestBuilder<'a, P>

§

impl<'a, P = Query> !RefUnwindSafe for RequestBuilder<'a, P>

§

impl<'a, P> Send for RequestBuilder<'a, P>
where P: Send,

§

impl<'a, P> Sync for RequestBuilder<'a, P>
where P: Sync,

§

impl<'a, P> Unpin for RequestBuilder<'a, P>
where P: Unpin,

§

impl<'a, P> UnsafeUnpin for RequestBuilder<'a, P>

§

impl<'a, P = Query> !UnwindSafe for RequestBuilder<'a, P>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V