[][src]Enum aws_lambda_events::encodings::Body

pub enum Body {
    Empty,
    Text(String),
    Binary(Vec<u8>),
}

Representation of http request and response bodies as supported by API Gateway and ALBs.

These come in three flavors

  • Empty ( no body )
  • Text ( text data )
  • Binary ( binary data )

Body types can be Deref and AsRef'd into [u8] types much like the hyper crate

Examples

Body types are inferred with From implementations.

Text

Types like String, str whose type reflects text produce Body::Text variants

assert!(match aws_lambda_events::encodings::Body::from("text") {
  aws_lambda_events::encodings::Body::Text(_) => true,
  _ => false
})

Binary

Types like Vec<u8> and &[u8] whose types reflect raw bytes produce Body::Binary variants

assert!(match aws_lambda_events::encodings::Body::from("text".as_bytes()) {
  aws_lambda_events::encodings::Body::Binary(_) => true,
  _ => false
})

Binary responses bodies will automatically get based64 encoded to meet API Gateway's response expectations.

Empty

The unit type ( () ) whose type represents an empty value produces Body::Empty variants

assert!(match aws_lambda_events::encodings::Body::from(()) {
  aws_lambda_events::encodings::Body::Empty => true,
  _ => false
})

For more information about API Gateway's body types, refer to this documentation.

Variants

Empty

An empty body

Text(String)

A body containing string data

Binary(Vec<u8>)

A body containing binary data

Implementations

impl Body[src]

pub fn from_maybe_encoded(is_base64_encoded: bool, body: &str) -> Body[src]

Decodes body, if needed.

Panics

Panics when aws communicates to handler that request is base64 encoded but it can not be base64 decoded

Trait Implementations

impl AsRef<[u8]> for Body[src]

impl Clone for Body[src]

impl Debug for Body[src]

impl Default for Body[src]

impl Deref for Body[src]

type Target = [u8]

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for Body[src]

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

impl<'a> From<&'a str> for Body[src]

impl From<()> for Body[src]

impl From<Cow<'static, [u8]>> for Body[src]

impl From<Cow<'static, str>> for Body[src]

impl From<String> for Body[src]

impl From<Vec<u8, Global>> for Body[src]

impl PartialEq<Body> for Body[src]

impl<'a> Serialize for Body[src]

impl StructuralPartialEq for Body[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.