Skip to content

Commit 7314eb0

Browse files
committed
Further renaming
1 parent ece6093 commit 7314eb0

File tree

13 files changed

+64
-69
lines changed

13 files changed

+64
-69
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17-
with:
18-
submodules: true
1917

2018
- name: Setup Rust
2119
uses: dtolnay/rust-toolchain@315e265cd78dad1e1dcf3a5074f6d6c47029d5aa

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
publish:
9-
if: github.repository == 'rquickjs/rquickjs-module'
9+
if: github.repository == 'rquickjs/rquickjs-extension'
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout repository

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rquickjs-extension"
3-
repository = "https://github.com/rquickjs/rquickjs-module"
3+
repository = "https://github.com/rquickjs/rquickjs-extension"
44
description = "An extension system for rquickjs"
55
license = "MIT"
66
authors = [

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# rquickjs module
1+
# rquickjs extension
22

3-
[![github](https://img.shields.io/badge/github-rquickjs/rquickjs-module.svg?style=for-the-badge&logo=github)](https://github.com/rquickjs/rquickjs-module)
4-
[![crates](https://img.shields.io/crates/v/rquickjs-module.svg?style=for-the-badge&color=fc8d62&logo=rust)](https://crates.io/crates/rquickjs-module)
3+
[![github](https://img.shields.io/badge/github-rquickjs/rquickjs-extension.svg?style=for-the-badge&logo=github)](https://github.com/rquickjs/rquickjs-extension)
4+
[![crates](https://img.shields.io/crates/v/rquickjs-extension.svg?style=for-the-badge&color=fc8d62&logo=rust)](https://crates.io/crates/rquickjs-extension)
55

6-
This is an extension to [rquickjs](https://github.com/DelSkayn/rquickjs) to allow the ecosystem to create more unified Rust modules.
6+
This is a complement to [rquickjs](https://github.com/DelSkayn/rquickjs) to allow the ecosystem to create more unified Rust extensions.
77

8-
The goal was to create a better version of [`ModuleDef`](https://docs.rs/rquickjs/latest/rquickjs/module/trait.ModuleDef.html) that would allow it to have options as input and set global.
8+
The goal was to create a more generic version of [`ModuleDef`](https://docs.rs/rquickjs/latest/rquickjs/module/trait.ModuleDef.html) that would allow it to have options and/or set global values.
99

10-
For example, a `fetch` module using `ModuleDefExt` could set a global `fetch` function and have as options an allowlist of domains.
10+
For example, a `fetch` extension could set a global `fetch` function and have as options an allowlist of domains.
1111

12-
## Using modules
12+
## Using extensions
1313

14-
If you are a consumer of modules create using that crate, here is how you can import them in your runtime.
14+
If you are a consumer of extensions created using that crate, here is how you can import them in your runtime.
1515

1616
```rust
1717
use rquickjs::AsyncRuntime;
18-
use rquickjs_module::ModuleLoader;
18+
use rquickjs_extension::ExtensionBuilder;
1919

2020
#[tokio::main]
2121
async fn main() {
2222
let rt = AsyncRuntime::new().unwrap();
2323

24-
let (loader, resolver, initalizer) = ModuleLoader::builder().with_module(MyModule).build();
24+
let (loader, resolver, initalizer) = ExtensionBuilder::new().with_module(MyExtension).build();
2525

2626
rt.set_loader(resolver, loader).await;
2727

@@ -36,37 +36,37 @@ async fn main() {
3636
}
3737
```
3838

39-
## Creating modules
39+
## Creating extensions
4040

41-
For the base case, replace the `ModuleDef` by an implementation of `ModuleDefExt`.
41+
For the base case, replace the `ModuleDef` by an implementation of `Extension`.
4242

4343
```rust
4444
use rquickjs::{Ctx, JsLifetime, Object, Result};
45-
use rquickjs_module::{ModuleDefExt, ModuleImpl};
45+
use rquickjs_extension::{Extension, ModuleImpl};
4646

4747
#[derive(JsLifetime, Debug)]
48-
struct MyModuleOptions {
48+
struct MyExtensionOptions {
4949
user: String,
5050
}
5151

52-
struct MyModule {
53-
options: MyModuleOptions,
52+
struct MyExtension {
53+
options: MyExtensionOptions,
5454
}
5555

56-
impl MyModule {
56+
impl MyExtension {
5757
pub fn new<T: Into<String>>(user: T) -> Self {
5858
Self {
59-
options: MyModuleOptions {
59+
options: MyExtensionOptions {
6060
user: user.into(),
6161
},
6262
}
6363
}
6464
}
6565

66-
impl ModuleDefExt<MyModuleOptions> for MyModule {
66+
impl Extension<MyExtensionOptions> for MyExtension {
6767
// Use `ModuleImpl` when you want a Javascript module.
6868
// The options generic is not required.
69-
type Implementation = ModuleImpl<MyModuleOptions>;
69+
type Implementation = ModuleImpl<MyExtensionOptions>;
7070

7171
fn implementation() -> &'static Self::Implementation {
7272
// This is the same as the implementation of `ModuleDef`
@@ -83,34 +83,34 @@ impl ModuleDefExt<MyModuleOptions> for MyModule {
8383
}
8484
}
8585

86-
fn options(self) -> MyModuleOptions {
86+
fn options(self) -> MyExtensionOptions {
8787
self.options
8888
}
8989

90-
fn globals(globals: &Object<'_>, options: &MyModuleOptions) -> Result<()> {
90+
fn globals(globals: &Object<'_>, options: &MyExtensionOptions) -> Result<()> {
9191
// Set your globals here
9292
globals.set("global_user", options.user.clone())?;
9393
Ok(())
9494
}
9595
}
9696
```
9797

98-
At runtime, this module results in:
98+
At runtime, this extension results in:
9999

100100
- A global variable named `global_user`
101101
- An importable module `import { user } from "my-module"`
102102

103103
### Globals only
104104

105-
If you only need to set globals and do **NOT** want an actual module that the Javascript can import, use `GlobalsOnly` for the implementation.
105+
If you only need to set globals and do **NOT** want a Javascript module, use `GlobalsOnly` for the implementation.
106106

107107
```rust
108108
use rquickjs::{Object, Result};
109-
use rquickjs_module::{ModuleDefExt, GlobalsOnly};
109+
use rquickjs_extension::{Extension, GlobalsOnly};
110110

111-
struct MyModule;
111+
struct MyExtension;
112112

113-
impl ModuleDefExt for MyModule {
113+
impl Extension for MyExtension {
114114
type Implementation = GlobalsOnly;
115115

116116
fn implementation() -> &'static Self::Implementation {
@@ -130,10 +130,10 @@ impl ModuleDefExt for MyModule {
130130
You can also use the macro for a simpler experience:
131131

132132
```rust
133-
use rquickjs_module::globals_only_module;
133+
use rquickjs_module::globals_only;
134134

135-
struct MyModule;
136-
globals_only_module!(MyModule, |globals| {
135+
struct MyExtension;
136+
globals_only!(MyExtension, |globals| {
137137
// Set your globals here
138138
globals.set("hello", "world".to_string())?;
139139
Ok(())

src/definition.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use rquickjs::{
33
Ctx, Object, Result,
44
};
55

6-
/// A trait for defining Javascript module and globals in Rust
7-
/// with options.
6+
/// A trait for defining an extension with options.
87
///
98
/// # Example
109
///
@@ -59,7 +58,7 @@ use rquickjs::{
5958
/// }
6059
/// ```
6160
pub trait Extension<O = ()> {
62-
type Implementation: ModuleImplementationType<O>;
61+
type Implementation: ExtensionType<O>;
6362

6463
fn globals(_globals: &Object<'_>, _options: &O) -> Result<()> {
6564
Ok(())
@@ -71,11 +70,11 @@ pub trait Extension<O = ()> {
7170
}
7271

7372
/// Marker trait for implementation types
74-
pub trait ModuleImplementationType<T> {}
73+
pub trait ExtensionType<T> {}
7574

7675
/// Implementation type when you only need to define globals
7776
pub struct GlobalsOnly;
78-
impl<T> ModuleImplementationType<T> for GlobalsOnly {}
77+
impl<T> ExtensionType<T> for GlobalsOnly {}
7978

8079
/// Implementation type when you need to define a module and
8180
/// optionally globals.
@@ -84,4 +83,4 @@ pub struct ModuleImpl<O = ()> {
8483
pub evaluate: for<'js> fn(&Ctx<'js>, &Exports<'js>, &O) -> Result<()>,
8584
pub name: &'static str,
8685
}
87-
impl<T> ModuleImplementationType<T> for ModuleImpl<T> {}
86+
impl<T> ExtensionType<T> for ModuleImpl<T> {}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//! An improved module system for rquickjs
1+
//! An extension system for rquickjs
22
//!
3-
//! This is an extension to [rquickjs](https://github.com/DelSkayn/rquickjs)
4-
//! to allow the ecosystem to create more unified Rust modules.
3+
//! This is a complement to [rquickjs](https://github.com/DelSkayn/rquickjs)
4+
//! to allow the ecosystem to create more unified Rust extensions.
55
//!
6-
//! The goal was to create a better version of
6+
//! The goal was to create a more generic version of
77
//! [`ModuleDef`](rquickjs::module::ModuleDef)
8-
//! that would allow it to have options as input and set global.
8+
//! that would allow it to have options and/or set global values.
99
1010
pub use self::definition::{Extension, GlobalsOnly, ModuleImpl};
1111
pub use self::loader::{ExtensionBuilder, GlobalInitializer, ModuleLoader, ModuleResolver};

src/loader/loader.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use rquickjs::{loader::Loader, Ctx, Error, Module, Result};
44

55
use super::ModuleLoadFn;
66

7-
/// Rquickjs [`Loader`](rquickjs::loader::Loader) for Rust modules
8-
/// defined using [`ModuleDefExt`](crate::ModuleDefExt).
9-
///
10-
/// See [`ModuleLoaderBuilder`] for usage.
7+
/// Rquickjs [`Loader`](rquickjs::loader::Loader) for modules
8+
/// defined using [`Extension`](crate::Extension).
119
pub struct ModuleLoader {
1210
modules: HashMap<&'static str, ModuleLoadFn>,
1311
}

src/loader/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn load_module_func<D: ModuleDef>(ctx: Ctx<'_>, name: Vec<u8>) -> Result<Module<
2626
///
2727
/// # Example
2828
/// ```rust
29-
/// use rquickjs_module::{ModuleLoader, ModuleDefExt, ModuleImpl};
29+
/// use rquickjs_extension::{Extension, ModuleImpl};
3030
///
3131
/// struct MyExtension;
3232
///

src/loader/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rquickjs::{
66
};
77

88
/// Rquickjs [`Resolver`](rquickjs::loader::Resolver) for modules
9-
/// defined using [`ModuleDefExt`](crate::ModuleDefExt).
9+
/// defined using [`Extension`](crate::Extension).
1010
pub struct ModuleResolver {
1111
inner: BuiltinResolver,
1212
}

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[macro_export]
2-
macro_rules! globals_only_module {
2+
macro_rules! globals_only {
33
($name:ident, |$globals:ident| { $($t:tt)* }) => {
44
impl Extension for $name {
55
type Implementation = GlobalsOnly;

0 commit comments

Comments
 (0)