Enum aws_lambda_events::encodings::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 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

Tuple Fields of Text

0: String
Binary(Vec<u8>)

A body containing binary data

Tuple Fields of Binary

0: Vec<u8>

Implementations

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

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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.

Deserialize this value from the given Serde deserializer. Read more

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.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

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.