Struct rustyscript::Module
source · pub struct Module { /* private fields */ }
Expand description
Represents a pice of javascript for execution. Must be ESM formatted
Implementations§
source§impl Module
impl Module
sourcepub fn new(filename: &str, contents: &str) -> Self
pub fn new(filename: &str, contents: &str) -> Self
Creates a new Module
instance with the given filename and contents.
If filename is relative it will be resolved to the current working dir at runtime
Arguments
filename
- A string representing the filename of the module.contents
- A string containing the contents of the module.
Returns
A new Module
instance.
Example
use rustyscript::Module;
let module = Module::new("module.js", "console.log('Hello, World!');");
sourcepub fn load(filename: &str) -> Result<Self, Error>
pub fn load(filename: &str) -> Result<Self, Error>
Loads a Module
instance from a file with the given filename.
Arguments
filename
- A string representing the filename of the module file.
Returns
A Result
containing the loaded Module
instance or an std::io::Error
if there
are issues reading the file.
Example
use rustyscript::Module;
let module = Module::load("src/ext/rustyscript/rustyscript.js")?;
sourcepub fn load_dir(directory: &str) -> Result<Vec<Self>, Error>
pub fn load_dir(directory: &str) -> Result<Vec<Self>, Error>
Attempt to load all js/ts files in a given directory Fails if any of the files cannot be loaded
Arguments
directory
- A string representing the target directory
Returns
A Result
containing a vec of loaded Module
instances or an std::io::Error
if there
are issues reading a file.
Example
use rustyscript::Module;
let all_modules = Module::load_dir("src/ext/rustyscript")?;
Trait Implementations§
source§impl<'de> Deserialize<'de> for Module
impl<'de> Deserialize<'de> for Module
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq for Module
impl PartialEq for Module
impl Eq for Module
impl StructuralEq for Module
impl StructuralPartialEq for Module
Auto Trait Implementations§
impl RefUnwindSafe for Module
impl Send for Module
impl Sync for Module
impl Unpin for Module
impl UnwindSafe for Module
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.