Skip to main content

Crate serverless_fn

Crate serverless_fn 

Source
Expand description

Serverless Function Library

A Rust library that simplifies the development and invocation of serverless functions. Allows calling serverless functions as if they were ordinary functions, with deployment strategy determined by crate feature flags.

§Features

  • Simplified Interface: Same syntax as regular function calls
  • Smart Deployment: Automatic deployment strategy based on feature flags
  • Local Debugging: Test without actual deployment
  • Type Safety: Compile-time type checking for parameters and return values

§Example

use serverless_fn::{serverless, ServerlessError};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Post {
    pub id: u64,
    pub title: String,
    pub content: String,
}

#[serverless]
pub async fn read_posts(how_many: usize, query: String) -> Result<Vec<Post>, ServerlessError> {
    Ok((0..how_many)
        .map(|i| Post {
            id: i as u64,
            title: format!("Post {}", i),
            content: format!("Content of post {}", i),
        })
        .collect())
}

§Feature Flags

  • remote_call: Enable remote invocation mode (default)
  • local_call: Enable local function call mode
  • json_serialization: Use JSON serialization (default)
  • postcard_serialization: Use Postcard serialization
  • mock_server: Enable mock server for testing
  • telemetry: Enable telemetry and monitoring

Re-exports§

pub use error::ServerlessError;
pub use server::FunctionServer;
pub use server::FunctionHandler;
pub use server::FunctionRegistry;
pub use server::ServerConfig;
pub use transport::http::HttpTransport;
pub use config::Config;
pub use config::ConfigBuilder;
pub use config::DeployStrategy;

Modules§

client
Client runtime for invoking serverless functions.
config
Configuration management module.
error
Error handling module.
serializer
Serialization/Deserialization module.
server
Server module for running serverless functions as HTTP services.
telemetry
Telemetry and monitoring module.
transport
Transport layer abstraction for HTTP communication.

Attribute Macros§

serverless
Attribute macro for marking a function as a serverless function.