Expand description
The native Rust SDK for Encore.
Unlike the Go and TypeScript SDKs (which reach the runtime over a C ABI / napi),
this crate links the Rust encore_sdk_core directly — Rust calling Rust, 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 with an encore.service.json ({ "name": ..., "lang": "rust" }) and ordinary Rust code. Trait-based services with #[encore::service]
/ #[endpoint] and HTTP serving are a later milestone.
Re-exports§
pub use env::app_meta;pub use encore_sdk_core::telemetry::opentelemetry;
Modules§
- config
- Application config: typed values a service reads, written in TOML or JSON files beside the code, and changed while the app runs.
- cron
- Cron jobs: requests Encore makes of a service on a schedule.
- env
- Metadata about the running application — its environment, build, deployment and API gateways.
- log
- The console log backend.
initinstalls Encore’s logger as thelogcrate’s global: each record at info and up, and the runtime’s own linesRUST_LOG(elseENCORE_RUNTIME_LOG) enables, prints on stderr in the Encore log format, with the trace and span ids ofContext::current, for the log collector.ENCORE_LOG_FORMATandENCORE_NOLOGoverride the format. The runtime’s lines (theencoreandencore_*crates’) log underencore.runtime, their target inencore.runtime.target. - metrics
- Metrics: counters, gauges and histograms of what an app does.
- objects
- Object storage buckets. Declared at module scope; resolved from the runtime on use.
- pubsub
- Pub/Sub topics and subscriptions. Topics are typed by the message they carry and declared at module scope; a subscription names its topic and the function that handles its messages.
- secrets
- Application secrets. Declared at module scope and resolved from the runtime.
- services
- Reaching the app’s other services.
- shutdown
- Graceful shutdown on SIGTERM or SIGINT (Ctrl+C/Ctrl+Break on Windows).
- storage
- Storage resources: databases an app declares and Encore provisions.
- telemetry
- Tracing. Encore records its spans and metrics through its own
tracer provider and
meter provider, never the
opentelemetryglobals, which the runtime leaves to the app: pass the providers to instrumentation libraries, or install them as the globals. Infra calls parent their spans onopentelemetry::Context::current. Logs print throughcrate::log. - testing
- Tests. Under
encore testevery test gets infrastructure of its own — databases, buckets and topics no other test sees — with nothing to set up:
Macros§
Structs§
- Error
- An error returned by an Encore SDK operation or an API endpoint handler.
Enums§
- ErrCode
- A gRPC-style error code, the same set the rest of Encore uses.
Functions§
- initialize
- Eagerly initialize the runtime, so an app fails fast at startup rather than on first resource use. Optional — any resource access triggers initialization.
- run_
blocking - Block the calling thread until a shutdown signal, then drain infrastructure and exit. The usual way to keep a service process alive that serves no requests of its own.
- tokio_
handle - A handle to the core runtime’s tokio runtime, for apps that need to spawn onto it (e.g. background infra tasks).