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 or N-API),
4//! this crate links `encore_sdk_core` directly with no marshalling layer.
5//!
6//! Infrastructure resources are declared as module-scope `static`s using `const`
7//! constructors, mirroring Encore's other SDKs:
8//!
9//! ```ignore
10//! use encore::{pubsub, secrets};
11//! use encore::storage::postgres;
12//! use encore::pubsub::Topic;
13//! use serde::{Serialize, Deserialize};
14//!
15//! static DB: postgres::Database = postgres::Database::new("hello").migrations("./migrations");
16//!
17//! #[derive(Serialize, Deserialize)]
18//! struct SignupEvent { user_id: String }
19//!
20//! static SIGNUPS: Topic<SignupEvent> = Topic::new("signups");
21//!
22//! static API_KEY: secrets::Secret = secrets::Secret::new("ApiKey");
23//! ```
24//!
25//! A service is a directory containing an `encore.service.json` (`{ "name": ..., "lang":
26//! "rust" }`) and ordinary Rust code.
27
28// For the tests of `#[encore::test]`, whose output names this crate.
29#[cfg(test)]
30extern crate self as encore;
31
32mod error;
33mod runtime;
34
35pub mod config;
36mod console_log;
37pub mod cron;
38pub mod env;
39pub mod frontends;
40#[cfg(feature = "gateway")]
41pub mod gateway;
42pub mod gateways;
43/// The standard logging facade, usable with [`telemetry::log::logger`].
44pub use ::log;
45pub mod metrics;
46pub mod objects;
47#[doc(hidden)]
48pub mod perm;
49pub mod pubsub;
50pub mod redaction;
51pub mod reqctx;
52pub mod secrets;
53pub mod services;
54pub mod shutdown;
55pub mod storage;
56pub mod telemetry;
57pub mod testing;
58
59/// The OpenTelemetry API implemented by Encore's tracer and meter providers.
60pub use encore_sdk_core::telemetry::opentelemetry;
61
62pub use error::{ErrCode, Error};
63
64/// Marks a test function (like `#[tokio::test]`) and registers it with Encore
65/// before it runs. See [`testing`].
66///
67/// ```ignore
68/// #[encore::test]
69/// async fn creates_a_user() -> Result<(), encore::Error> {
70/// // …
71/// }
72///
73/// #[encore::test(flavor = "multi_thread", worker_threads = 2)]
74/// async fn handles_concurrent_requests() {
75/// // …
76/// }
77/// ```
78pub use encore_macros::test;
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};