@@ -84,7 +84,7 @@ pub fn attr_macro_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
84
84
. into ( )
85
85
}
86
86
87
- /// Enables a HTTP- server main function, for creating [HTTP servers].
87
+ /// Enables a HTTP server main function, for creating [HTTP servers].
88
88
///
89
89
/// [HTTP servers]: https://docs.rs/wstd/latest/wstd/http/server/index.html
90
90
///
@@ -148,9 +148,38 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
148
148
149
149
:: wstd:: wasi:: http:: proxy:: export!( TheServer with_types_in :: wstd:: wasi) ;
150
150
151
- // In case the user needs it, provide a `main` function so that the
152
- // code compiles.
153
- fn main( ) { unreachable!( "HTTP-server components should be run wth `handle` rather than `main`" ) }
151
+ // Provide an actual function named `main`.
152
+ //
153
+ // WASI HTTP server components don't use a traditional `main` function.
154
+ // They export a function named `handle` which takes a `Request`
155
+ // argument, and which may be called multiple times on the same
156
+ // instance. To let users write a familiar `fn main` in a file
157
+ // named src/main.rs, we provide this `wstd::main` macro, which
158
+ // transforms the user's `fn main` into the appropriate `handle`
159
+ // function.
160
+ //
161
+ // However, when the top-level file is named src/main.rs, rustc
162
+ // requires there to be a function named `main` somewhere in it. This
163
+ // requirement can be disabled using `#![no_main]`, however we can't
164
+ // use that automatically because macros can't contain inner
165
+ // attributes, and we don't want to require users to add `#![no_main]`
166
+ // in their own code.
167
+ //
168
+ // So, we include a definition of a function named `main` here, which
169
+ // isn't intended to ever be called, and exists just to satify the
170
+ // requirement for a `main` function.
171
+ //
172
+ // Users could use `#![no_main]` if they want to. Or, they could name
173
+ // their top-level file src/lib.rs and add
174
+ // ```toml
175
+ // [lib]
176
+ // crate-type = ["cdylib"]
177
+ // ```
178
+ // to their Cargo.toml. With either of these, this "main" function will
179
+ // be ignored as dead code.
180
+ fn main( ) {
181
+ unreachable!( "HTTP server components should be run with `handle` rather than `run`" )
182
+ }
154
183
}
155
184
. into ( )
156
185
}
0 commit comments