Trait tencent_scf::convert::FromReader[][src]

pub trait FromReader: Sized {
    type Error;
    fn from_reader<Reader: Read + Send>(
        reader: Reader
    ) -> Result<Self, Self::Error>; }

Trait for conversion from raw incoming invocation to event type

Custom event should implement this trait so that the runtime can deserialize the incoming invocation into the desired event.

Implement the Trait

One needs to provide a method that can consume a raw byte reader into the desired type.

use tencent_scf::convert::FromReader;

// Our custom event type
struct Event(String);

// Simply read everything from the reader.
impl FromReader for Event {
    type Error = std::io::Error;

    fn from_reader<Reader: std::io::Read + Send>(
        mut reader: Reader,
    ) -> Result<Self, Self::Error> {
        let mut buf = String::new();
        reader.read_to_string(&mut buf)?;
        Ok(Event(buf))
    }
}

Associated Types

type Error[src]

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

Loading content...

Required methods

fn from_reader<Reader: Read + Send>(reader: Reader) -> Result<Self, Self::Error>[src]

Consume the reader and produce the deserialized output

Loading content...

Implementations on Foreign Types

impl<T> FromReader for Request<T> where
    Event: TryInto<Request<T>, Error = RequestParseError>, 
[src]

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

Enable auto deserialization for Request types

The query part of the uri will be stored as ext::QueryString in the extension of the request, leaving only the path in the uri().

Currently only two types of payload is supported

  • Request<String>: The body will be treated as a utf-8 string.
  • Request<Vec<u8>>: The request body will be assumed as a base64-encoded string. The runtime will decode it to Vec<u8>

type Error = <Event as TryInto<Request<T>>>::Error

impl FromReader for Vec<u8>[src]

Auto deserialization into a byte array.

type Error = Error

impl FromReader for String[src]

Auto deserialization into a string.

type Error = Error

Loading content...

Implementors

impl<T> FromReader for T where
    T: DeserializeOwned + AsJson
[src]

This is supported on crate feature json only.

Auto deserilization for types that are serde::Deserialize and marked as AsJson.

type Error = Error

Loading content...