Enum Body

Source
pub enum Body<'a> {
    Empty,
    String(Cow<'a, str>),
    Json(Cow<'a, str>),
    Bytes(Cow<'a, [u8]>),
}
Expand description

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.

Implementations§

Source§

impl Body<'_>

Source

pub fn default_content_type(&self) -> &str

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");
Source

pub fn as_str(&self) -> Option<&str>

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");
Source

pub fn as_bytes(&self) -> &[u8]

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());
Source

pub fn as_json<'b, T>(&'b self) -> Result<T>
where T: Deserialize<'b>,

Deserializes the body as JSON to the requested type.

§Examples
use azure_functions::http::Body;
use std::borrow::Cow;
use serde::Deserialize;

#[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§

Source§

impl<'a> Clone for Body<'a>

Source§

fn clone(&self) -> Body<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Body<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Body<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a [u8]> for Body<'a>

Source§

fn from(data: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&Value> for Body<'_>

Source§

fn from(data: &Value) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Body<'a>

Source§

fn from(data: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Body<'_>

Source§

fn from(data: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Body<'_>

Source§

fn from(data: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Body<'_>

Source§

fn from(data: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Into<Body<'a>> for Blob

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for CosmosDbDocument

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for EventHubMessage

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for GenericInput

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for OrchestrationData

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for QueueMessage

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for ServiceBusMessage

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for SignalRConnectionInfo

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for Table

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for Value

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> Into<Body<'a>> for Vec<CosmosDbDocument>

Source§

fn into(self) -> Body<'a>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Body<'a>

§

impl<'a> RefUnwindSafe for Body<'a>

§

impl<'a> Send for Body<'a>

§

impl<'a> Sync for Body<'a>

§

impl<'a> Unpin for Body<'a>

§

impl<'a> UnwindSafe for Body<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more