Struct Builder
struct Builder { ... }
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: Self, status: T) -> Builder where T: TryInto<StatusCode>, <T as TryInto<StatusCode>>::Error: Into<crate::Error>Set the HTTP status for this response.
By default this is
200.Examples
# use *; let response = builder .status .body .unwrap;fn version(self: 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: Self, key: K, value: V) -> Builder where K: TryInto<HeaderName>, <K as TryInto<HeaderName>>::Error: Into<crate::Error>, V: TryInto<HeaderValue>, <V as TryInto<HeaderValue>>::Error: Into<crate::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: &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(self: &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: Self, extension: T) -> Builder where T: Clone + Any + Send + Sync + 'staticAdds an extension to this builder
Examples
# use *; let response = builder .extension .body .unwrap; assert_eq!;fn extensions_ref(self: &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(self: &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: 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;
impl Debug for Builder
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for Builder
fn default() -> Builder
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
impl<T> Any for Builder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Builder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Builder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Builder
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Builder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Builder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>