spin_sdk/
lib.rs

1//! The Rust Spin SDK.
2
3#![deny(missing_docs)]
4#![cfg_attr(docsrs, feature(doc_cfg))]
5
6#[cfg(test)]
7mod test;
8
9/// Key/Value storage.
10pub mod key_value;
11
12/// SQLite storage for Spin 2 and earlier. Applications that do not require
13/// this backward compatibility should use the [`sqlite3`] module instead.
14pub mod sqlite;
15/// SQLite storage.
16pub mod sqlite3;
17
18/// Large Language Model (Serverless AI) APIs
19pub mod llm;
20
21pub use spin_macro::*;
22
23/// WASIp3 HTTP APIs and helpers.
24///
25/// **The contents of this module are unstable.** Module APIs may change in future releases,
26/// and may not work with future versions of Spin (as they bind to a particular WASI RC
27/// which Spin will retire once a stable WASIp3 is available)/
28#[cfg(feature = "wasip3-unstable")]
29#[cfg_attr(docsrs, doc(cfg(feature = "wasip3-unstable")))]
30pub mod http_wasip3 {
31    pub use spin_wasip3_http::*;
32
33    /// Marks an `async fn` as an HTTP component entrypoint for Spin.
34    ///
35    /// The `#[http_service]` attribute designates an asynchronous function as the
36    /// handler for incoming HTTP requests in a Spin component using the WASI Preview 3
37    /// (`wasip3`) HTTP ABI.  
38    ///
39    /// When applied, this macro generates the necessary boilerplate to export the
40    /// function to the Spin runtime as a valid HTTP handler. The function must be
41    /// declared `async` and take a single argument implementing
42    /// [`FromRequest`], typically
43    /// [`Request`], and must return a type that
44    /// implements [`IntoResponse`].
45    ///
46    /// # Requirements
47    ///
48    /// - The annotated function **must** be `async`.
49    /// - The function’s parameter type must implement [`FromRequest`].
50    /// - The return type must implement [`IntoResponse`].
51    /// - The Spin manifest must specify `executor = { type = "wasip3-unstable" }`
52    ///
53    /// If the function is not asynchronous, the macro emits a compile-time error.
54    ///
55    /// # Example
56    ///
57    /// ```ignore
58    /// use spin_sdk::http_wasip3::{http_service, Request, IntoResponse};
59    ///
60    /// #[http_service]
61    /// async fn my_handler(request: Request) -> impl IntoResponse {
62    ///   // Your logic goes here
63    /// }
64    /// ```
65    ///
66    /// # Generated Code
67    ///
68    /// The macro expands into a module containing a `Spin` struct that implements the
69    /// WASI `http.handler/Guest` interface, wiring the annotated function as the
70    /// handler’s entrypoint. This allows the function to be invoked automatically
71    /// by the Spin runtime when HTTP requests are received.
72    pub use spin_wasip3_http_macro::http_service;
73}
74
75#[doc(hidden)]
76/// Module containing wit bindgen generated code.
77///
78/// This is only meant for internal consumption.
79pub mod wit {
80    #![allow(missing_docs)]
81
82    wit_bindgen::generate!({
83        world: "platform",
84        path: "./wit",
85        with: {
86            "wasi:io/error@0.2.0": ::wasi::io::error,
87            "wasi:io/streams@0.2.0": ::wasi::io::streams,
88            "wasi:io/poll@0.2.0": ::wasi::io::poll,
89        },
90        generate_all,
91    });
92    pub use fermyon::spin2_0_0 as v2;
93    pub use spin::postgres3_0_0::postgres as pg3;
94    pub use spin::postgres4_0_0::postgres as pg4;
95    pub use spin::sqlite::sqlite as sqlite3;
96}
97
98#[export_name = concat!("spin-sdk-version-", env!("SDK_VERSION"))]
99extern "C" fn __spin_sdk_version() {}
100
101#[cfg(feature = "export-sdk-language")]
102#[export_name = "spin-sdk-language-rust"]
103extern "C" fn __spin_sdk_language() {}
104
105#[export_name = concat!("spin-sdk-commit-", env!("SDK_COMMIT"))]
106extern "C" fn __spin_sdk_hash() {}
107
108pub mod http;
109
110#[allow(missing_docs)]
111pub mod mqtt;
112
113#[allow(missing_docs)]
114pub mod redis;
115
116pub mod pg;
117pub mod pg3;
118pub mod pg4;
119
120pub mod mysql;
121
122pub mod variables;
123
124#[doc(hidden)]
125pub use wit_bindgen;