Skip to content

Commit acd5ac0

Browse files
committed
docs
1 parent 8248e32 commit acd5ac0

5 files changed

Lines changed: 48 additions & 34 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ keywords = ["rust", "javascript", "deno", "runtime", "embedding"]
1111
categories = ["web-programming", "network-programming", "api-bindings", "compilers", "development-tools::ffi"]
1212
readme = "readme.md"
1313

14+
[package.metadata.docs.rs]
15+
all-features = true
16+
1417
[features]
1518
default = ["worker", "safe_extensions"]
1619

@@ -241,9 +244,6 @@ checksum = { version = "0.2.1", optional = true }
241244
version-sync = "0.9.5"
242245
criterion = "0.5.1"
243246

244-
[package.metadata.docs.rs]
245-
all-features = true
246-
247247
[[example]]
248248
name = "custom_threaded_worker"
249249
required-features = ["worker"]

examples/thread_safety.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
/// See `examples/default_threaded_worker` and `examples/custom_threaded_worker`
77
/// for a more flexible way to run rustyscript in a threaded environment
88
///
9-
use rustyscript::{module, static_runtime, Error, StaticModule};
9+
use rustyscript::{module, static_runtime, Error, RuntimeOptions, StaticModule};
10+
use std::time::Duration;
1011

11-
static_runtime!(RUNTIME);
12+
static_runtime!(RUNTIME, {
13+
RuntimeOptions {
14+
timeout: Duration::from_secs(5),
15+
..Default::default()
16+
}
17+
});
1218

1319
// Modules can be defined statically using this macro!
1420
static MY_MODULE: StaticModule = module!(

src/ext/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,59 @@ pub mod runtime;
8888
/// Options for configuring extensions
8989
pub struct ExtensionOptions {
9090
/// Options specific to the `deno_web`, `deno_fetch` and `deno_net` extensions
91+
///
92+
/// Requires the `web` feature to be enabled
9193
#[cfg(feature = "web")]
9294
pub web: web::WebOptions,
9395

9496
/// Optional seed for the `deno_crypto` extension
97+
///
98+
/// Requires the `crypto` feature to be enabled
9599
#[cfg(feature = "crypto")]
96100
pub crypto_seed: Option<u64>,
97101

98102
/// Configures the stdin/out/err pipes for the `deno_io` extension
103+
///
104+
/// Requires the `io` feature to be enabled
99105
#[cfg(feature = "io")]
100106
pub io_pipes: Option<deno_io::Stdio>,
101107

102108
/// Optional path to the directory where the webstorage extension will store its data
109+
///
110+
/// Requires the `webstorage` feature to be enabled
103111
#[cfg(feature = "webstorage")]
104112
pub webstorage_origin_storage_dir: Option<std::path::PathBuf>,
105113

106114
/// Optional cache configuration for the `deno_cache` extension
115+
///
116+
/// Requires the `cache` feature to be enabled
107117
#[cfg(feature = "cache")]
108118
pub cache: Option<deno_cache::CreateCache<cache::CacheBackend>>,
109119

110120
/// Filesystem implementation for the `deno_fs` extension
121+
///
122+
/// Requires the `fs` feature to be enabled
111123
#[cfg(feature = "fs")]
112124
pub filesystem: deno_fs::FileSystemRc,
113125

114126
/// Shared in-memory broadcast channel for the `deno_broadcast_channel` extension
115127
/// Also used by `WebWorker` to communicate with the main thread, if node is enabled
128+
///
129+
/// Requires the `broadcast_channel` feature to be enabled
116130
#[cfg(feature = "broadcast_channel")]
117131
pub broadcast_channel: deno_broadcast_channel::InMemoryBroadcastChannel,
118132

119133
/// Key-value store for the `deno_kv` extension
134+
///
135+
/// Requires the `kv` feature to be enabled
120136
#[cfg(feature = "kv")]
121137
pub kv_store: kv::KvStore,
122138

123139
/// Package resolver for the `deno_node` extension
124140
/// `RustyResolver` allows you to select the base dir for modules
125141
/// as well as the filesystem implementation to use
142+
///
143+
/// Requires the `node_experimental` feature to be enabled
126144
#[cfg(feature = "node_experimental")]
127145
pub node_resolver: std::sync::Arc<node::RustyResolver>,
128146
}

src/snapshot_builder.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl SnapshotBuilder {
9696
}
9797

9898
/// Creates a new instance of the runtime with the provided options and a pre-configured tokio runtime.
99-
/// See [`Runtime::new`] for more information.
99+
/// See [`crate::Runtime::new`] for more information.
100100
///
101101
/// # Errors
102102
/// Can fail if the deno runtime initialization fails (usually issues with extensions)
@@ -161,7 +161,7 @@ impl SnapshotBuilder {
161161
}
162162

163163
/// Advance the JS event loop by a single tick
164-
/// See [`Runtime::await_event_loop`] for fully running the event loop
164+
/// See [`crate::Runtime::await_event_loop`] for fully running the event loop
165165
///
166166
/// Returns true if the event loop has pending work, or false if it has completed
167167
///
@@ -194,7 +194,7 @@ impl SnapshotBuilder {
194194
/// Run the JS event loop to completion, or until a timeout is reached
195195
/// Required when using the `_immediate` variants of functions
196196
///
197-
/// This is the blocking variant of [`Runtime::await_event_loop`]
197+
/// This is the blocking variant of [`crate::Runtime::await_event_loop`]
198198
///
199199
/// # Arguments
200200
/// * `options` - Options for the event loop polling, see [`deno_core::PollEventLoopOptions`]
@@ -307,7 +307,7 @@ impl SnapshotBuilder {
307307
///
308308
/// Note that synchronous functions are run synchronously. Returned promises will be run asynchronously, however.
309309
///
310-
/// See [`Runtime::call_function`] for an example
310+
/// See [`crate::Runtime::call_function`] for an example
311311
///
312312
/// # Arguments
313313
/// * `module_context` - Optional handle to a module to search - if None, or if the search fails, the global context is used
@@ -390,7 +390,7 @@ impl SnapshotBuilder {
390390
/// Calls a javascript function within the Deno runtime by its name and deserializes its return value.
391391
/// Will not attempt to resolve promises, or run the event loop
392392
/// Promises can be returned by specifying the return type as [`crate::js_value::Promise`]
393-
/// The event loop should be run using [`Runtime::await_event_loop`]
393+
/// The event loop should be run using [`crate::Runtime::await_event_loop`]
394394
///
395395
/// # Arguments
396396
/// * `module_context` - Optional handle to a module to search - if None, or if the search fails, the global context is used
@@ -480,7 +480,7 @@ impl SnapshotBuilder {
480480
/// - The event loop is resolved, and
481481
/// - If the value is a promise, the promise is resolved
482482
///
483-
/// See [`Runtime::get_value`] for an example
483+
/// See [`crate::Runtime::get_value`] for an example
484484
///
485485
/// # Arguments
486486
/// * `module_context` - Optional handle to a module to search - if None, or if the search fails, the global context is used
@@ -508,7 +508,7 @@ impl SnapshotBuilder {
508508
/// Get a value from a runtime instance
509509
/// Will not attempt to resolve promises, or run the event loop
510510
/// Promises can be returned by specifying the return type as [`crate::js_value::Promise`]
511-
/// The event loop should be run using [`Runtime::await_event_loop`]
511+
/// The event loop should be run using [`crate::Runtime::await_event_loop`]
512512
///
513513
/// # Arguments
514514
/// * `module_context` - Optional handle to a module to search - if None, or if the search fails, the global context is used
@@ -550,7 +550,7 @@ impl SnapshotBuilder {
550550
/// And call functions
551551
///
552552
/// Blocks until the module has been executed AND the event loop has fully resolved
553-
/// See [`Runtime::load_module_async`] for a non-blocking variant, or use with async
553+
/// See [`crate::Runtime::load_module_async`] for a non-blocking variant, or use with async
554554
/// background tasks
555555
///
556556
/// # Arguments
@@ -590,7 +590,7 @@ impl SnapshotBuilder {
590590
/// And call functions
591591
///
592592
/// Returns a future that resolves to the handle for the loaded module
593-
/// Makes no attempt to fully resolve the event loop - call [`Runtime::await_event_loop`]
593+
/// Makes no attempt to fully resolve the event loop - call [`crate::Runtime::await_event_loop`]
594594
/// to resolve background tasks and async listeners
595595
///
596596
/// # Arguments
@@ -603,7 +603,7 @@ impl SnapshotBuilder {
603603
/// # Errors
604604
/// Can fail if the module cannot be loaded, or execution fails
605605
///
606-
/// See [`Runtime::load_module`] for an example
606+
/// See [`crate::Runtime::load_module`] for an example
607607
pub async fn load_module_async(&mut self, module: &Module) -> Result<ModuleHandle, Error> {
608608
self.inner.load_modules(None, vec![module]).await
609609
}
@@ -612,7 +612,7 @@ impl SnapshotBuilder {
612612
/// And call functions.
613613
///
614614
/// Blocks until all modules have been executed AND the event loop has fully resolved
615-
/// See [`Runtime::load_module_async`] for a non-blocking variant, or use with async
615+
/// See [`crate::Runtime::load_module_async`] for a non-blocking variant, or use with async
616616
/// background tasks
617617
///
618618
/// This will load 'module' as the main module, and the others as side-modules.
@@ -660,13 +660,13 @@ impl SnapshotBuilder {
660660
/// And call functions.
661661
///
662662
/// Returns a future that resolves to the handle for the loaded module
663-
/// Makes no attempt to resolve the event loop - call [`Runtime::await_event_loop`] to
663+
/// Makes no attempt to resolve the event loop - call [`crate::Runtime::await_event_loop`] to
664664
/// resolve background tasks and async listeners
665665
///
666666
/// This will load 'module' as the main module, and the others as side-modules.
667667
/// Only one main module can be loaded per runtime
668668
///
669-
/// See [`Runtime::load_modules`] for an example
669+
/// See [`crate::Runtime::load_modules`] for an example
670670
///
671671
/// # Arguments
672672
/// * `module` - A `Module` object containing the module's filename and contents.

src/static_runtime.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//! runtime.eval::<()>("console.log('Hello, world!')")
3333
//! })
3434
//! }
35+
//! ```
3536
use crate::{Error, Runtime, RuntimeOptions};
3637
use std::cell::{OnceCell, RefCell, RefMut};
3738

@@ -90,6 +91,7 @@ impl<'a> StaticRuntimeLock<'a> {
9091
/// runtime.eval::<()>("console.log('Hello, world!')")
9192
/// })
9293
/// }
94+
/// ```
9395
pub struct StaticRuntime {
9496
init_options: fn() -> RuntimeOptions,
9597
cell: OnceCell<RefCell<Result<Runtime, Error>>>,
@@ -158,23 +160,9 @@ impl StaticRuntime {
158160
/// The first argument is the name of the static runtime
159161
/// The second argument is an optional block that should return a `RuntimeOptions` instance
160162
///
161-
/// # Example
162-
/// ```rust
163-
/// use rustyscript::{static_runtime, RuntimeOptions};
164-
/// use std::time::Duration;
165-
///
166-
/// static_runtime!(MY_DEFAULT_RUNTIME);
167-
///
168-
/// static_runtime!(MY_CUSTOM_RUNTIME, {
169-
/// RuntimeOptions {
170-
/// timeout: Duration::from_secs(5),
171-
/// ..Default::default()
172-
/// }
173-
/// });
174-
/// ```
163+
/// See [`crate::static_runtime`] for an example
175164
///
176-
/// The resulting runtime can be accessed using `with`, following by either `lock` or `with_runtime`
177-
/// See [`static_runtime::StaticRuntime`] for more information
165+
/// The resulting runtime can be accessed using `with`, which accepts a closure that takes a mutable reference to the runtime
178166
#[macro_export]
179167
macro_rules! static_runtime {
180168
($name:ident, $options:block) => {
@@ -190,6 +178,8 @@ macro_rules! static_runtime {
190178
= const { $crate::static_runtime::StaticRuntime::new(|| $options) };
191179
}
192180

181+
/// Perform an operation on the runtime instance
182+
#[allow(dead_code)]
193183
pub fn with<T, F>(callback: F) -> Result<T, $crate::Error>
194184
where
195185
F: FnMut(&mut $crate::Runtime) -> Result<T, $crate::Error>,

0 commit comments

Comments
 (0)