@@ -160,22 +160,56 @@ impl StaticRuntime {
160160/// The first argument is the name of the static runtime
161161/// The second argument is an optional block that should return a `RuntimeOptions` instance
162162///
163- /// See [`crate::static_runtime`] for an example
163+ /// Can be used with default `RuntimeOptions` like so:
164+ /// ```rust
165+ /// use rustyscript::{RuntimeOptions, Error, static_runtime};
166+ /// use std::time::Duration;
167+ ///
168+ /// static_runtime!(MY_DEFAULT_RUNTIME);
169+ ///
170+ /// fn main() -> Result<(), Error> {
171+ /// MY_DEFAULT_RUNTIME::with(|runtime| {
172+ /// runtime.eval::<()>("console.log('Hello, world!')")
173+ /// })
174+ /// }
175+ /// ```
176+ ///
177+ /// Or with custom `RuntimeOptions`:
178+ /// ```rust
179+ /// use rustyscript::{Error, RuntimeOptions, static_runtime};
180+ /// use std::time::Duration;
164181///
165- /// The resulting runtime can be accessed using `with`, which accepts a closure that takes a mutable reference to the runtime
182+ /// static_runtime!(MY_CUSTOM_RUNTIME, {
183+ /// RuntimeOptions {
184+ /// timeout: Duration::from_secs(5),
185+ /// ..Default::default()
186+ /// }
187+ /// });
188+ ///
189+ /// fn main() -> Result<(), Error> {
190+ /// MY_CUSTOM_RUNTIME::with(|runtime| {
191+ /// runtime.eval::<()>("console.log('Hello, world!')")
192+ /// })
193+ /// }
194+ /// ```
166195#[ macro_export]
167196macro_rules! static_runtime {
168197 ( $name: ident, $options: block) => {
169198 /// A thread-local static runtime instance
170199 /// Use the `with` method to access the runtime
171200 #[ allow( non_snake_case) ]
172201 mod $name {
173- #[ allow( unused_imports) ]
174- use super :: * ;
202+
203+ fn init_options( ) -> $crate:: RuntimeOptions {
204+ #[ allow( unused_imports) ]
205+ use super :: * ;
206+
207+ $options
208+ }
175209
176210 thread_local! {
177211 static RUNTIME : $crate:: static_runtime:: StaticRuntime
178- = const { $crate:: static_runtime:: StaticRuntime :: new( || $options ) } ;
212+ = const { $crate:: static_runtime:: StaticRuntime :: new( init_options ) } ;
179213 }
180214
181215 /// Perform an operation on the runtime instance
0 commit comments