spin_sdk/
lib.rs

1//! The Rust Spin SDK.
2
3#![deny(missing_docs)]
4
5#[cfg(test)]
6mod test;
7
8/// Key/Value storage.
9pub mod key_value;
10
11/// SQLite storage.
12pub mod sqlite;
13
14/// Large Language Model APIs
15pub mod llm;
16
17/// Exports the procedural macros for writing handlers for Spin components.
18pub use spin_macro::*;
19
20#[doc(hidden)]
21/// Module containing wit bindgen generated code.
22///
23/// This is only meant for internal consumption.
24pub mod wit {
25    #![allow(missing_docs)]
26
27    wit_bindgen::generate!({
28        world: "platform",
29        path: "./wit",
30        with: {
31            "wasi:io/error@0.2.0": spin_executor::bindings::wasi::io::error,
32            "wasi:io/streams@0.2.0": spin_executor::bindings::wasi::io::streams,
33            "wasi:io/poll@0.2.0": spin_executor::bindings::wasi::io::poll,
34        }
35    });
36    pub use fermyon::spin2_0_0 as v2;
37    pub use spin::postgres::postgres as pg3;
38}
39
40/// Needed by the export macro
41///
42/// See [this commit](https://github.com/bytecodealliance/wit-bindgen/pull/394/commits/9d2ea88f986f4a883ba243449e3a070cac18958e) for more info.
43#[cfg(target_arch = "wasm32")]
44#[doc(hidden)]
45pub use wit::__link_section;
46
47#[export_name = concat!("spin-sdk-version-", env!("SDK_VERSION"))]
48extern "C" fn __spin_sdk_version() {}
49
50#[cfg(feature = "export-sdk-language")]
51#[export_name = "spin-sdk-language-rust"]
52extern "C" fn __spin_sdk_language() {}
53
54#[export_name = concat!("spin-sdk-commit-", env!("SDK_COMMIT"))]
55extern "C" fn __spin_sdk_hash() {}
56
57/// Helpers for building Spin `wasi-http` components.
58pub mod http;
59
60/// Implementation of the spin mqtt interface.
61#[allow(missing_docs)]
62pub mod mqtt {
63    pub use super::wit::v2::mqtt::{Connection, Error, Payload, Qos};
64}
65
66/// Implementation of the spin redis interface.
67#[allow(missing_docs)]
68pub mod redis {
69    use std::hash::{Hash, Hasher};
70
71    pub use super::wit::v2::redis::{Connection, Error, Payload, RedisParameter, RedisResult};
72
73    impl PartialEq for RedisResult {
74        fn eq(&self, other: &Self) -> bool {
75            use RedisResult::*;
76            match (self, other) {
77                (Nil, Nil) => true,
78                (Status(a), Status(b)) => a == b,
79                (Int64(a), Int64(b)) => a == b,
80                (Binary(a), Binary(b)) => a == b,
81                _ => false,
82            }
83        }
84    }
85
86    impl Eq for RedisResult {}
87
88    impl Hash for RedisResult {
89        fn hash<H: Hasher>(&self, state: &mut H) {
90            use RedisResult::*;
91
92            match self {
93                Nil => (),
94                Status(s) => s.hash(state),
95                Int64(v) => v.hash(state),
96                Binary(v) => v.hash(state),
97            }
98        }
99    }
100}
101
102/// Implementation of the spin postgres db interface.
103pub mod pg;
104
105/// Implementation of the spin postgres v3 db interface.
106pub mod pg3;
107
108/// Implementation of the Spin MySQL database interface.
109pub mod mysql;
110
111#[doc(inline)]
112pub use wit::v2::variables;
113
114#[doc(hidden)]
115pub use wit_bindgen;