Skip to main content

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;
38mod console_log;
39pub mod cron;
40pub mod env;
41pub mod frontends;
42#[cfg(feature = "gateway")]
43pub mod gateway;
44pub mod gateways;
45/// The standard logging facade, usable with [`telemetry::log::logger`].
46pub use ::log;
47pub mod metrics;
48pub mod objects;
49#[doc(hidden)]
50pub mod perm;
51pub mod pubsub;
52pub mod reqctx;
53pub mod secrets;
54pub mod services;
55pub mod shutdown;
56pub mod storage;
57pub mod telemetry;
58pub mod testing;
59
60/// The OTel API Encore's tracer and meter providers implement.
61pub use encore_sdk_core::telemetry::opentelemetry;
62
63pub use error::{ErrCode, Error};
64
65pub use encore_macros::test;
66/// Marks a test, as `#[tokio::test]` does, and tells Encore about it before it
67/// runs. See [`testing`].
68///
69/// ```ignore
70/// #[encore::test]
71/// async fn creates_a_user() -> Result<(), encore::Error> {
72///     // …
73/// }
74///
75/// #[encore::test(flavor = "multi_thread", worker_threads = 2)]
76/// async fn handles_concurrent_requests() {
77///     // …
78/// }
79/// ```
80/// Registers `#[encore(sensitive)]` on fields for schema-based redaction.
81///
82/// This does not change Serde serialization.
83///
84/// ```
85/// #[derive(serde::Serialize, serde::Deserialize, encore::Schema)]
86/// struct Signup {
87///     user_id: String,
88///     #[encore(sensitive)]
89///     email: String,
90/// }
91/// ```
92pub use encore_macros::Schema;
93pub use env::app_meta;
94pub use runtime::{initialize, run_blocking, tokio_handle};