AssemblyLift
HomeRepo
v0.2
v0.2
  • Welcome to AssemblyLift
  • Learn AssemblyLift
    • Getting Started
    • Services
    • Functions
      • Rust Functions
    • How to Build
    • How to Deploy
  • Resources
    • The Lexicon
    • Tutorial: Build a "todo list" backend with AssemblyLift
Powered by GitBook
On this page
  • Dependencies
  • Handler Definition

Was this helpful?

  1. Learn AssemblyLift
  2. Functions

Rust Functions

PreviousFunctionsNextHow to Build

Last updated 4 years ago

Was this helpful?

Dependencies

An AssemblyLift function written in Rust is a . It requires several crates to be imported, which provide the necessary plumbing to make our Rust crate an AssemblyLift function.

When making a new function via asml make the generated Cargo.toml should have included these crates. However, you should also ensure that you are using the latest patch version of each.

Cargo.toml
[dependencies]
asml_core = { version = "0.2", package = "assemblylift-core-guest" }
asml_core_io = { version = "0.2", package = "assemblylift-core-io-guest" }
asml_awslambda = { version = "0.2", package = "assemblylift-awslambda-guest" }

The core crate provides the GuestCore trait, which defines an interface for communicating with the cloud runtime (logging, low-level success/error response, etc). This trait is implemented by AwsLambdaClient which is provided by the awslambda crate.

The core-io crate provides the IO system; this is AssemblyLift's Future execution system supporting async/await.

Handler Definition

The awslambda crate provides a macro called handler! which wraps up all the details of initializing the module, and provides a concise entry point for our function.

The handler! macro exports a function called handler which provides the entry-point from the runtime host.

Only one handler can be defined per function. Calling the handler! macro more than once will produce a compiler error.

lib.rs
extern crate asml_awslambda;

use asml_core::GuestCore;
use asml_awslambda::{AwsLambdaClient, LambdaContext};

handler!(context: LambdaContext<ApiGatewayEvent>, async {
    // function code
    // supports .await
})

The extern crate statement is required to bring statics & externs into scope which are defined in the crate.

The context value is accessible from within the function code, and provides access to details of the function invocation, include the input payload and authorization data.

library crate