Enum lambda_http::Body[][src]

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

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 lambda_http::Body::from("text") {
  lambda_http::Body::Text(_) => true,
  _ => false
})

Binary

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

assert!(match lambda_http::Body::from("text".as_bytes()) {
  lambda_http::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 lambda_http::Body::from(()) {
  lambda_http::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

Tuple Fields of Text

0: String
Binary(Vec<u8>)

A body containing binary data

Tuple Fields of Binary

0: Vec<u8>

Trait Implementations

Performs the conversion.

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.