quickjs_rusty/value/
module.rs

1use std::ops::Deref;
2
3use crate::errors::*;
4use crate::value::*;
5
6/// A bytecode compiled module.
7pub struct JsModule {
8    value: OwnedJsValue,
9}
10
11impl JsModule {
12    pub fn try_from_value(value: OwnedJsValue) -> Result<Self, ValueError> {
13        if !value.is_module() {
14            Err(ValueError::Internal(format!(
15                "Expected a compiled function, got {:?}",
16                value.tag()
17            )))
18        } else {
19            Ok(Self { value })
20        }
21    }
22
23    pub fn into_value(self) -> OwnedJsValue {
24        self.value
25    }
26}
27
28/// The result of loading QuickJs bytecode.
29/// Either a function or a module.
30pub enum JsCompiledValue {
31    Function(JsCompiledFunction),
32    Module(JsModule),
33}
34
35impl Deref for JsModule {
36    type Target = OwnedJsValue;
37
38    fn deref(&self) -> &Self::Target {
39        &self.value
40    }
41}