Skip to main content

spin_sdk/
lib.rs

1//! The Rust Spin SDK.
2//!
3//! This crate is the main entry point for building [Spin](https://spinframework.dev)
4//! components in Rust. Each capability is exposed as a feature-gated
5//! module. All features are enabled by default; disable `default-features`
6//! and pick only what you need to slim down compile times.
7//!
8//! The [`http_service`] and [`redis_subscriber`] attribute macros
9//! generate the boilerplate required to expose a component to the
10//! Spin runtime.
11
12#![deny(missing_docs)]
13#![cfg_attr(docsrs, feature(doc_cfg))]
14
15/// Re-export entrypoint macros
16pub use spin_macro::{dependencies, http_service, redis_subscriber};
17
18/// Incoming and outgoing HTTP requests.
19#[cfg(feature = "http")]
20#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
21pub mod http;
22
23/// Persistent key-value storage.
24#[cfg(feature = "key-value")]
25#[cfg_attr(docsrs, doc(cfg(feature = "key-value")))]
26pub mod key_value;
27
28/// Large-language-model inference.
29#[cfg(feature = "llm")]
30#[cfg_attr(docsrs, doc(cfg(feature = "llm")))]
31pub mod llm;
32
33/// MQTT message publishing.
34#[cfg(feature = "mqtt")]
35#[cfg_attr(docsrs, doc(cfg(feature = "mqtt")))]
36pub mod mqtt;
37
38/// MySQL database access.
39#[cfg(feature = "mysql")]
40#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
41pub mod mysql;
42
43/// PostgreSQL database access.
44#[cfg(feature = "pg")]
45#[cfg_attr(docsrs, doc(cfg(feature = "pg")))]
46pub mod pg;
47
48/// Redis storage and pub/sub.
49#[cfg(feature = "redis")]
50#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
51pub mod redis;
52
53/// SQLite database access.
54#[cfg(feature = "sqlite")]
55#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
56pub mod sqlite;
57
58/// Time-related functions.
59pub mod time;
60
61/// Application variable lookup.
62#[cfg(feature = "variables")]
63#[cfg_attr(docsrs, doc(cfg(feature = "variables")))]
64pub mod variables;
65
66#[export_name = concat!("spin-sdk-version-", env!("SDK_VERSION"))]
67extern "C" fn __spin_sdk_version() {}
68
69#[cfg(feature = "export-sdk-language")]
70#[export_name = "spin-sdk-language-rust"]
71extern "C" fn __spin_sdk_language() {}
72
73#[export_name = concat!("spin-sdk-commit-", env!("SDK_COMMIT"))]
74extern "C" fn __spin_sdk_hash() {}
75
76pub use wasip3::{self, wit_bindgen};
77
78#[doc(hidden)]
79pub mod experimental {
80    #![allow(missing_docs)]
81    use crate::wit_bindgen;
82
83    wit_bindgen::generate!({
84        runtime_path: "crate::wit_bindgen::rt",
85        world: "spin-sdk-experimental",
86        path: "wit",
87        generate_all,
88    });
89}
90
91#[cfg(test)]
92mod test;