Skip to content

Commit 32f31aa

Browse files
authored
Merge pull request #90 from itowlson/wasip3-rustdoc
Update P3 docs and error message
2 parents fc509ab + 5074cea commit 32f31aa

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ description = """
1313
The Spin Rust SDK makes it easy to build Spin components in Rust.
1414
"""
1515

16+
[package.metadata.docs.rs]
17+
all-features = true
18+
rustdoc-args = ["--cfg", "docsrs"]
19+
1620
[lib]
1721
name = "spin_sdk"
1822

crates/spin-wasip3-http-macro/src/lib.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,14 @@
11
use proc_macro::TokenStream;
22
use quote::quote;
33

4-
/// Marks an `async fn` as an HTTP component entrypoint for Spin.
5-
///
6-
/// The `#[http_service]` attribute designates an asynchronous function as the
7-
/// handler for incoming HTTP requests in a Spin component using the WASI Preview 3
8-
/// (`wasip3`) HTTP ABI.
9-
///
10-
/// When applied, this macro generates the necessary boilerplate to export the
11-
/// function to the Spin runtime as a valid HTTP handler. The function must be
12-
/// declared `async` and take a single argument implementing
13-
/// [`FromRequest`](::spin_sdk::http_wasip3::FromRequest), typically
14-
/// [`Request`](::spin_sdk::http_wasip3::Request), and must return a type that
15-
/// implements [`IntoResponse`](::spin_sdk::http_wasip3::IntoResponse).
16-
///
17-
/// # Requirements
18-
///
19-
/// - The annotated function **must** be `async`.
20-
/// - The function’s parameter type must implement [`FromRequest`].
21-
/// - The return type must implement [`IntoResponse`].
22-
///
23-
/// If the function is not asynchronous, the macro emits a compile-time error.
24-
///
25-
/// # Example
26-
///
27-
/// ```ignore
28-
/// use spin_sdk::http_wasip3::{http_service, Request, IntoResponse};
29-
///
30-
/// #[http_service]
31-
/// async fn my_handler(request: Request) -> impl IntoResponse {
32-
/// // Your logic goes here
33-
/// }
34-
/// ```
35-
///
36-
/// # Generated Code
37-
///
38-
/// The macro expands into a module containing a `Spin` struct that implements the
39-
/// WASI `http.handler/Guest` interface, wiring the annotated function as the
40-
/// handler’s entrypoint. This allows the function to be invoked automatically
41-
/// by the Spin runtime when HTTP requests are received.
424
#[proc_macro_attribute]
435
pub fn http_service(_attr: TokenStream, item: TokenStream) -> TokenStream {
446
let func = syn::parse_macro_input!(item as syn::ItemFn);
457

468
if func.sig.asyncness.is_none() {
479
return syn::Error::new_spanned(
4810
func.sig.fn_token,
49-
"the `#[http_component]` function must be `async`",
11+
"the `#[http_service]` function must be `async`",
5012
)
5113
.to_compile_error()
5214
.into();

crates/spin-wasip3-http/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Experimental Rust SDK for WASIp3 http.
1+
//! Experimental Rust SDK for WASIp3 HTTP.
22
33
#![deny(missing_docs)]
44

@@ -328,14 +328,14 @@ where
328328
}
329329
}
330330

331-
/// Helpers for consuming an [`IncomingBody`].
331+
/// Helpers for consuming an [`wasip3::http_compat::IncomingBody`].
332332
///
333333
/// This module provides extension traits and utilities for working with
334-
/// [`IncomingBody`] instances, such as streaming or collecting the entire
334+
/// [`wasip3::http_compat::IncomingBody`] instances, such as streaming or collecting the entire
335335
/// body into memory.
336336
///
337337
/// These helpers make it easier to transform low-level streaming body types
338-
/// into higher-level forms (e.g., [`Bytes`]) for simplified data handling.
338+
/// into higher-level forms (e.g., [`bytes::Bytes`]) for simplified data handling.
339339
pub mod body {
340340
use bytes::Bytes;
341341
use http_body_util::{BodyDataStream, BodyExt};

src/lib.rs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The Rust Spin SDK.
22
33
#![deny(missing_docs)]
4+
#![cfg_attr(docsrs, feature(doc_cfg))]
45

56
#[cfg(test)]
67
mod test;
@@ -19,14 +20,56 @@ pub mod llm;
1920

2021
pub use spin_macro::*;
2122

22-
/// WASIp3 HTTP APIs and helpers
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)/
2328
#[cfg(feature = "wasip3-unstable")]
29+
#[cfg_attr(docsrs, doc(cfg(feature = "wasip3-unstable")))]
2430
pub mod http_wasip3 {
25-
/// Re-exports the helpers types for converting between WASIp3 HTTP types and
26-
/// Rust ecosystem HTTP types.
2731
pub use spin_wasip3_http::*;
28-
/// Re-exports the macro to enable WASIp3 HTTP handlers
29-
pub use spin_wasip3_http_macro::*;
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;
3073
}
3174

3275
#[doc(hidden)]

0 commit comments

Comments
 (0)