encore/lib.rs
1//! The native Rust SDK for [Encore](https://encore.dev).
2//!
3//! Unlike the Go and TypeScript SDKs (which reach the runtime over a C ABI / napi),
4//! this crate links the Rust `encore_sdk_core` directly — Rust calling Rust, no
5//! marshalling layer.
6//!
7//! Infrastructure resources are declared as module-scope `static`s using `const`
8//! constructors, mirroring Encore's other SDKs:
9//!
10//! ```ignore
11//! use encore::{pubsub, secrets};
12//! use encore::storage::postgres;
13//! use encore::pubsub::Topic;
14//! use serde::{Serialize, Deserialize};
15//!
16//! static DB: postgres::Database = postgres::Database::new("hello").migrations("./migrations");
17//!
18//! #[derive(Serialize, Deserialize)]
19//! struct SignupEvent { user_id: String }
20//!
21//! static SIGNUPS: Topic<SignupEvent> = Topic::new("signups");
22//!
23//! static API_KEY: secrets::Secret = secrets::Secret::new("ApiKey");
24//! ```
25//!
26//! A service is a directory with an `encore.service.json` (`{ "name": ..., "lang":
27//! "rust" }`) and ordinary Rust code. Trait-based services with `#[encore::service]`
28//! / `#[endpoint]` and HTTP serving are a later milestone.
29
30// For the tests of `#[encore::test]`, whose output names this crate.
31#[cfg(test)]
32extern crate self as encore;
33
34mod error;
35mod runtime;
36
37pub mod config;
38pub mod cron;
39pub mod env;
40pub mod log;
41pub mod metrics;
42pub mod objects;
43#[doc(hidden)]
44pub mod perm;
45pub mod pubsub;
46pub mod secrets;
47pub mod services;
48pub mod shutdown;
49pub mod storage;
50pub mod telemetry;
51pub mod testing;
52
53/// The OTel API Encore's tracer and meter providers implement.
54pub use encore_sdk_core::telemetry::opentelemetry;
55
56pub use error::{ErrCode, Error};
57
58/// Marks a test, as `#[tokio::test]` does, and tells Encore about it before it
59/// runs. See [`testing`].
60///
61/// ```ignore
62/// #[encore::test]
63/// async fn creates_a_user() -> Result<(), encore::Error> {
64/// // …
65/// }
66///
67/// #[encore::test(flavor = "multi_thread", worker_threads = 2)]
68/// async fn handles_concurrent_requests() {
69/// // …
70/// }
71/// ```
72pub use encore_macros::test;
73pub use env::app_meta;
74pub use runtime::{initialize, run_blocking, tokio_handle};