[−][src]Enum azure_functions::http::Body
Represents the body of a HTTP request or response.
Variants
Empty
Represents an empty body.
String(Cow<'a, str>)
Represents a string body with a default content type of text/plain
.
Json(Cow<'a, str>)
Represents a JSON body with a default content type of application/json
.
Bytes(Cow<'a, [u8]>)
Represents a body from a slice of bytes with a default content type of application/octet-stream
.
Methods
impl<'_> Body<'_>
[src]
pub fn default_content_type(&self) -> &str
[src]
Gets the default content type for a body.
Returns application/json
for Body::Json
.
Returns application/octet-stream
for Body::Bytes
.
Returns text/plain
for all other Body
values.
Examples
use azure_functions::http::Body; let body: Body = [1, 2, 3][..].into(); assert_eq!(body.default_content_type(), "application/octet-stream");
pub fn as_str(&self) -> Option<&str>
[src]
Gets the body as a string.
Returns None if there is no valid string representation of the message.
Examples
use azure_functions::http::Body; use std::borrow::Cow; let body = Body::String(Cow::Borrowed("test")); assert_eq!(body.as_str().unwrap(), "test");
pub fn as_bytes(&self) -> &[u8]
[src]
Gets the body as a slice of bytes.
Examples
use azure_functions::http::Body; use std::borrow::Cow; let body = Body::String(Cow::Borrowed("test")); assert_eq!(body.as_bytes(), "test".as_bytes());
pub fn as_json<'b, T>(&'b self) -> Result<T> where
T: Deserialize<'b>,
[src]
T: Deserialize<'b>,
Deserializes the body as JSON to the requested type.
Examples
use azure_functions::http::Body; use std::borrow::Cow; #[derive(Deserialize)] struct Data { message: String } let body = Body::String(Cow::Borrowed(r#"{ "message": "hello" }"#)); let data = body.as_json::<Data>().unwrap(); assert_eq!(data.message, "hello");
Trait Implementations
impl<'a> Clone for Body<'a>
[src]
fn clone(&self) -> Body<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'_> Into<TypedData> for Body<'_>
[src]
impl<'a> From<&'a TypedData> for Body<'a>
[src]
impl<'a> From<&'a str> for Body<'a>
[src]
impl<'_> From<String> for Body<'_>
[src]
impl<'_, '_> From<&'_ Value> for Body<'_>
[src]
impl<'_> From<Value> for Body<'_>
[src]
impl<'a> From<&'a [u8]> for Body<'a>
[src]
impl<'_> From<Vec<u8>> for Body<'_>
[src]
impl<'a> Debug for Body<'a>
[src]
impl<'_> Display for Body<'_>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,