Expand description
The native Rust SDK for Encore.
Unlike the Go and TypeScript SDKs (which reach the runtime over a C ABI or N-API),
this crate links encore_sdk_core directly with no marshalling layer.
Infrastructure resources are declared as module-scope statics using const
constructors, mirroring Encore’s other SDKs:
ⓘ
use encore::{pubsub, secrets};
use encore::storage::postgres;
use encore::pubsub::Topic;
use serde::{Serialize, Deserialize};
static DB: postgres::Database = postgres::Database::new("hello").migrations("./migrations");
#[derive(Serialize, Deserialize)]
struct SignupEvent { user_id: String }
static SIGNUPS: Topic<SignupEvent> = Topic::new("signups");
static API_KEY: secrets::Secret = secrets::Secret::new("ApiKey");A service is a directory containing an encore.service.json ({ "name": ..., "lang": "rust" }) and ordinary Rust code.
Re-exports§
pub use env::app_meta;pub use ::log;pub use encore_sdk_core::telemetry::opentelemetry;
Modules§
- config
- Application configuration: typed values read by a service, defined in TOML or JSON files beside the code and updated dynamically while the app runs.
- cron
- Scheduled cron jobs that invoke an HTTP endpoint on your service.
- env
- Metadata about the running application — its environment, build, deployment, API gateways, and frontends.
- frontends
- Resolving URLs for the application’s frontends.
- gateways
- Resolving URLs for the application’s API gateways.
- metrics
- Application metrics: counters, up-down counters, gauges, and histograms.
- objects
- Object storage buckets, declared at module scope and resolved from the runtime on use.
- pubsub
- Pub/Sub topics and subscriptions.
- redaction
- Redact telemetry copies using the service’s deployed policy.
- reqctx
- Request Context: typed fields that travel with a request to every service it reaches (for example, the authenticated user).
- secrets
- Application secrets, declared at module scope and resolved from the runtime.
- services
- Calling other services in the application.
- shutdown
- Graceful shutdown on
SIGTERMorSIGINT(Ctrl+C/Ctrl+Breakon Windows). - storage
- Storage resources: databases an app declares and Encore provisions.
- telemetry
- Application-owned telemetry APIs.
- testing
- Testing support.
Macros§
Structs§
- Error
- An error returned by an Encore SDK operation or an API endpoint handler.
Enums§
- ErrCode
- A gRPC-style error code shared across Encore.
Functions§
- initialize
- Eagerly initializes the runtime so an application fails fast at startup rather than on first resource use.
- run_
blocking - Blocks the calling thread until a shutdown signal arrives, then drains infrastructure and exits.
- tokio_
handle - Returns a handle to the core runtime’s Tokio runtime, for applications that need to spawn background infrastructure tasks onto it.
Attribute Macros§
- test
- Marks a test function (like
#[tokio::test]) and registers it with Encore before it runs. Seetesting.
Derive Macros§
- Schema
- Registers
#[encore(sensitive)]on fields for schema-based redaction.