Trait tencent_scf::convert::IntoBytes[][src]

pub trait IntoBytes {
    type Error;
    fn into_bytes(self) -> Result<Vec<u8>, Self::Error>;
}

Trait for converting response into raw bytes.

Custom response should implement this trait so that runtime can send raw bytes to the upstream cloud.

Implement the Trait

One needs to provide a method that can consume the object and produce a byte array.

use tencent_scf::convert::IntoBytes;

// Our custom response type
struct Response(String);

// Simply turn a string into a byte array.
impl IntoBytes for Response {
    type Error = std::convert::Infallible;

    fn into_bytes(self) -> Result<Vec<u8>, Self::Error> {
        Ok(String::into_bytes(self.0))
    }
}

Associated Types

type Error[src]

Possible error during the conversion. std::fmt::Display is all the runtime needs.

Loading content...

Required methods

fn into_bytes(self) -> Result<Vec<u8>, Self::Error>[src]

Consume the object and serialize it into a byte array.

Loading content...

Implementations on Foreign Types

impl<T> IntoBytes for Response<T> where
    Response<T>: TryInto<WebResponse, Error = ResponseEncodeError>, 
[src]

This is supported on crate feature builtin-api-gateway only.

Enable auto serialization for Response types

Currently only two types of payload is supported

  • Response<String>: The body will be treated as a utf-8 string.
  • Response<Vec<u8>>: The body will be assumed to be binary format. The runtime will perform a base64 encoding to send it to the upstream cloud.

type Error = <Response<T> as TryInto<WebResponse>>::Error

impl IntoBytes for Vec<u8>[src]

Auto serialization for byte array (identity map).

type Error = Infallible

impl IntoBytes for String[src]

Auto serilization for string.

type Error = Infallible

Loading content...

Implementors

impl<T> IntoBytes for T where
    T: Serialize + AsJson
[src]

This is supported on crate feature json only.

Auto serilization for types that are serde::Serialize and marked as AsJson.

type Error = Error

Loading content...