1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use ;
/// A trait for defining an extension with options.
///
/// # Example
///
/// ```
/// use rquickjs::{Ctx, JsLifetime, Object, Result};
/// use rquickjs_extension::{Extension, ModuleImpl};
///
/// #[derive(JsLifetime, Debug)]
/// struct MyExtensionOptions {
/// user: String,
/// }
///
/// struct MyExtension {
/// options: MyExtensionOptions,
/// }
///
/// impl MyExtension {
/// pub fn new<T: Into<String>>(user: T) -> Self {
/// Self {
/// options: MyExtensionOptions {
/// user: user.into(),
/// },
/// }
/// }
/// }
///
/// impl Extension<MyExtensionOptions> for MyExtension {
/// type Implementation = ModuleImpl<MyExtensionOptions>;
///
/// fn implementation() -> &'static Self::Implementation {
/// &ModuleImpl {
/// declare: |decl| {
/// decl.declare("user")?;
/// Ok(())
/// },
/// evaluate: |ctx, exports, options| {
/// exports.export("user", options.user.clone())?;
/// Ok(())
/// },
/// name: "my-module",
/// }
/// }
///
/// fn options(self) -> MyExtensionOptions {
/// self.options
/// }
///
/// fn globals(globals: &Object<'_>, options: &MyExtensionOptions) -> Result<()> {
/// globals.set("user", options.user.clone())?;
/// Ok(())
/// }
/// }
/// ```
/// Marker trait for implementation types
/// Implementation type when you only need to define globals
;
/// Implementation type when you need to define a module and
/// optionally globals.