Trait tencent_scf::convert::FromReader [−][src]
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.
Required methods
fn from_reader<Reader: Read + Send>(reader: Reader) -> Result<Self, Self::Error>
[src]
Consume the reader
and produce the deserialized output
Implementations on Foreign Types
impl<T> FromReader for Request<T> where
Event: TryInto<Request<T>, Error = RequestParseError>,
[src]
Event: TryInto<Request<T>, Error = RequestParseError>,
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 toVec<u8>
type Error = <Event as TryInto<Request<T>>>::Error
fn from_reader<Reader: Read + Send>(reader: Reader) -> Result<Self, Self::Error>
[src]
impl FromReader for Vec<u8>
[src]
Auto deserialization into a byte array.
type Error = Error
fn from_reader<Reader: Read + Send>(
mut reader: Reader
) -> Result<Self, Self::Error>
[src]
mut reader: Reader
) -> Result<Self, Self::Error>
impl FromReader for String
[src]
Auto deserialization into a string.
type Error = Error
fn from_reader<Reader: Read + Send>(
mut reader: Reader
) -> Result<Self, Self::Error>
[src]
mut reader: Reader
) -> Result<Self, Self::Error>
Implementors
impl<T> FromReader for T where
T: DeserializeOwned + AsJson,
[src]
T: DeserializeOwned + AsJson,
json
only.Auto deserilization for types that are serde::Deserialize
and marked as AsJson
.