Struct Builder
pub struct Builder { /* private fields */ }
An HTTP response builder
This type can be used to construct an instance of Response through a
builder-like pattern.
Implementations
impl Builder
fn new() -> BuilderCreates a new default instance of
Builderto construct either aHeador aResponse.Examples
# use *; let response = new .status .body .unwrap;fn status<T>(self, status: T) -> Builder where T: TryInto<StatusCode>, <T as TryInto<StatusCode>>::Error: Into<Error>,Set the HTTP status for this response.
By default this is
200.Examples
# use *; let response = builder .status .body .unwrap;fn version(self, version: Version) -> BuilderSet the HTTP version for this response.
By default this is HTTP/1.1
Examples
# use *; let response = builder .version .body .unwrap;fn header<K, V>(self, key: K, value: V) -> Builder where K: TryInto<HeaderName>, <K as TryInto<HeaderName>>::Error: Into<Error>, V: TryInto<HeaderValue>, <V as TryInto<HeaderValue>>::Error: Into<Error>,Appends a header to this response builder.
This function will append the provided key/value as a header to the internal
HeaderMapbeing constructed. Essentially this is equivalent to callingHeaderMap::append.Examples
# use *; # use HeaderValue; let response = builder .header .header .header .body .unwrap;fn headers_ref(&self) -> Option<&HeaderMap<HeaderValue>>Get header on this response builder.
When builder has error returns None.
Example
# use Response; # use HeaderValue; let res = builder .header .header; let headers = res.headers_ref.unwrap; assert_eq!; assert_eq!;fn headers_mut(&mut self) -> Option<&mut HeaderMap<HeaderValue>>Get header on this response builder. when builder has error returns None
Example
# use *; # use HeaderValue; # use Builder; let mut res = builder; let headers = res.headers_ref.unwrap; assert_eq!; assert_eq!;fn extension<T>(self, extension: T) -> Builder where T: Clone + Any + Send + Sync + 'static,Adds an extension to this builder
Examples
# use *; let response = builder .extension .body .unwrap; assert_eq!;fn extensions_ref(&self) -> Option<&Extensions>Get a reference to the extensions for this response builder.
If the builder has an error, this returns
None.Example
# use Response; let res = builder.extension.extension; let extensions = res.extensions_ref.unwrap; assert_eq!; assert_eq!;fn extensions_mut(&mut self) -> Option<&mut Extensions>Get a mutable reference to the extensions for this response builder.
If the builder has an error, this returns
None.Example
# use Response; let mut res = builder.extension; let mut extensions = res.extensions_mut.unwrap; assert_eq!; extensions.insert; assert_eq!;fn body<T>(self, body: T) -> Result<Response<T>>"Consumes" this builder, using the provided
bodyto return a constructedResponse.Errors
This function may return an error if any previously configured argument failed to parse or get converted to the internal representation. For example if an invalid
headwas specified viaheader("Foo", "Bar\r\n")the error will be returned when this function is called rather than whenheaderwas called.Examples
# use *; let response = builder .body .unwrap;
Trait Implementations
impl Debug for Builder
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Builder
fn default() -> Builder
Auto Trait Implementations
impl !RefUnwindSafe for Builder
impl !UnwindSafe for Builder
impl Freeze for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
Blanket Implementations
impl<T> Any for Builder
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Builder
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Builder
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Builder
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Builder
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Builder
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>