pub trait FromReader: Sized {
type Error;
// Required method
fn from_reader<Reader: Read + Send>(
reader: Reader,
) -> Result<Self, Self::Error>;
}
Expand description
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))
}
}
Required Associated Types§
Sourcetype Error
type Error
Possible error during the conversion. std::fmt::Display
is all the runtime needs.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl FromReader for String
Auto deserialization into a string.
impl FromReader for String
Auto deserialization into a string.
Source§impl FromReader for Vec<u8>
Auto deserialization into a byte array.
impl FromReader for Vec<u8>
Auto deserialization into a byte array.
Source§impl<T> FromReader for Request<T>
Available on crate feature builtin-api-gateway
only.Enable auto deserialization for Request
types
impl<T> FromReader for Request<T>
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>
Implementors§
Source§impl<T> FromReader for Twhere
T: DeserializeOwned + AsJson,
Available on crate feature json
only.Auto deserilization for types that are serde::Deserialize
and marked as AsJson
.
impl<T> FromReader for Twhere
T: DeserializeOwned + AsJson,
json
only.Auto deserilization for types that are serde::Deserialize
and marked as AsJson
.