Function tencent_scf::start [−][src]
pub fn start<Event, Response, Error, ConvertEventError, ConvertResponseError, Function>(
f: Function
) where
Function: ServerlessComputeFunction<Event = Event, Response = Response, Error = Error> + RefUnwindSafe,
Event: FromReader<Error = ConvertEventError>,
Response: IntoBytes<Error = ConvertResponseError>,
Error: Display,
ConvertEventError: Display,
ConvertResponseError: Display,
Start the runtime with the given serverless compute function.
Typically this should be the last call in the main
function.
Panic
The runtime will panic if any of the following happens:
- Fail to initialize, for example, expected environment vairable not found.
- Fail to communicate to upstream cloud.
- Receive malformed response from upstream cloud.
The runtime will not panic if the serverless compute function panics. Instead, the panic will
be captured and properly sent to the upstream cloud. The runtime may not be able to capture
all kinds of panic, see std::panic::catch_unwind
for more information.
Example
use std::convert::Infallible; use serde::{Deserialize, Serialize}; use tencent_scf::{convert::AsJson, make_scf, start, Context}; // define a custom event #[derive(Deserialize)] struct CustomEvent { a: i32, b: i32, } // mark the custom event as json for auto deserialization impl AsJson for CustomEvent {} // define a custom response #[derive(Serialize)] struct CustomResponse { a_plus_b: i32, } // mark the custom response as json for auto serialization impl AsJson for CustomResponse {} fn main() { // make the scf let scf = make_scf( |event: CustomEvent, _context: Context| -> Result<CustomResponse, Infallible> { Ok(CustomResponse { a_plus_b: event.a + event.b, }) }, ); // start the runtime in the main function start(scf); }