Trait tencent_scf::ServerlessComputeFunction[][src]

pub trait ServerlessComputeFunction {
    type Event;
    type Response;
    type Error;
    fn call(
        &self,
        event: Self::Event,
        context: Context
    ) -> Result<Self::Response, Self::Error>; }

Main trait for a serverless compute function.

Note

Depending on whether the concrete type is unwind-safe, user should choose between start and start_uncatched to start the runtime. This trait doesn't imply RefUnwindSafe.

Implement the Trait

Using a closure should cover most of the cases. If a struct/enum is used, the trait can be implemented as:

use tencent_scf::{start, Context, ServerlessComputeFunction};
struct MyFunction {
    some_attribute: String,
}

impl ServerlessComputeFunction for MyFunction {
    // Type for input event
    type Event = String;
    // Type for output response
    type Response = String;
    // Type for possible error
    type Error = std::convert::Infallible;

    // Implement the execution of the function
    fn call(
        &self,
        event: Self::Event,
        context: Context,
    ) -> Result<Self::Response, Self::Error> {
        // We just concatenate the strings
        Ok(event + &self.some_attribute)
    }
}

start(MyFunction {
    some_attribute: "suffix".to_string(),
});

Associated Types

type Event[src]

The type for incoming event.

type Response[src]

The type for outgoing response.

type Error[src]

The type for error(s) during the execution of the function.

Loading content...

Required methods

fn call(
    &self,
    event: Self::Event,
    context: Context
) -> Result<Self::Response, Self::Error>
[src]

The actual execution of the function. Implementer is allowed to panic as it will be catched by the runtime.

Loading content...

Implementors

Loading content...