Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

Module

StructModule 

Source
pub struct Module {/* private fields */ }
Expand description

ECMAScript’sAbstract module record.

Implementations§

Source§

implModule

Source

pub fnparse<R:ReadChar>( src:Source<'_, R>, realm:Option<Realm>, context: &mutContext,) ->JsResult<Self>

Abstract operationParseModule ( sourceText, realm, hostDefined ).

Parses the providedsrc as an ECMAScript module, returning an error if parsing fails.

Source

pub fnsynthetic( export_names: &[JsString], evaluation_steps:SyntheticModuleInitializer, path:Option<PathBuf>, realm:Option<Realm>, context: &mutContext,) -> Self

Abstract operationCreateSyntheticModule ( exportNames, evaluationSteps, realm ).

Creates a new Synthetic Module from its list of exported names, its evaluation steps andoptionally a root realm.

Source

pub fnfrom_value_as_default(value:JsValue, context: &mutContext) -> Self

Create aModule from aJsValue, exporting that value as the default export.This will clone the module everytime it is initialized.

Source

pub fnparse_json(json:JsString, context: &mutContext) ->JsResult<Self>

Create a module that exports a single JSON value as the default export, from itsJSON string.

§Specification

This is a custom extension to the ECMAScript specification. The current proposalfor JSON modules is being considered inhttps://github.com/tc39/proposal-json-modulesand might differ from this implementation.

This method is provided as a convenience for hosts to create JSON modules.

§Errors

This will return an error if the JSON string is invalid or cannot be converted.

Source

pub fnrealm(&self) -> &Realm

Gets the realm of thisModule.

Source

pub fnhost_defined(&self) -> &HostDefined

Returns theECMAScript specification defined\[\[HostDefined\]\] field of theModule.

Source

pub fnload(&self, context: &mutContext) ->JsPromise

Abstract methodLoadRequestedModules ( [ hostDefined ] ).

Prepares the module for linking by loading all its module dependencies. Returns aJsPromisethat will resolve when the loading process either completes or fails.

Source

pub fnlink(&self, context: &mutContext) ->JsResult<()>

Abstract methodLink().

Prepares this module for evaluation by resolving all its module dependencies and initializingits environment.

§Note

This must only be called if theJsPromise returned byModule::load has fulfilled.

Source

pub fnevaluate(&self, context: &mutContext) ->JsPromise

Abstract methodEvaluate().

Evaluates this module, returning a promise for the result of the evaluation of this moduleand its dependencies.If the promise is rejected, hosts are expected to handle the promise rejection and rethrowthe evaluation error.

§Note

This must only be called if theModule::link method finished successfully.

Source

pub fnload_link_evaluate(&self, context: &mutContext) ->JsPromise

Loads, links and evaluates this module, returning a promise that will resolve after the modulefinishes its lifecycle.

§Examples
letloader = Rc::new(SimpleModuleLoader::new(Path::new(".")).unwrap());letmutcontext =&mutContext::builder()    .module_loader(loader.clone())    .build()    .unwrap();letsource = Source::from_bytes("1 + 3");letmodule = Module::parse(source,None, context).unwrap();loader.insert(Path::new("main.mjs").to_path_buf(), module.clone());letpromise = module.load_link_evaluate(context);context.run_jobs().unwrap();assert_eq!(    promise.state(),    PromiseState::Fulfilled(JsValue::undefined()));
Source

pub fnnamespace(&self, context: &mutContext) ->JsObject

Abstract operationGetModuleNamespace ( module ).

Gets theModule Namespace Object that represents this module’s exports.

Source

pub fnget_value<K>(&self, name: K, context: &mutContext) ->JsResult<JsValue>
where K:Into<PropertyKey>,

Get an exported value from the module.

Source

pub fnget_typed_fn<A, R>( &self, name:JsString, context: &mutContext,) ->JsResult<TypedJsFunction<A, R>>

Get an exported function, typed, from the module.

Source

pub fnpath(&self) ->Option<&Path>

Returns the path of the module, if it was created from a file or assigned.

Trait Implementations§

Source§

implClone forModule

Source§

fnclone(&self) ->Module

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
Source§

implDebug forModule

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

Formats the value using the given formatter.Read more
Source§

implDrop forModule

Source§

fndrop(&mut self)

Executes the destructor for this type.Read more
Source§

implFinalize forModule

Source§

fnfinalize(&self)

Cleanup logic for a type.
Source§

implHash forModule

Source§

fnhash<H:Hasher>(&self, state:&mut H)

Feeds this value into the givenHasher.Read more
1.3.0 ·Source§

fnhash_slice<H>(data: &[Self], state:&mut H)
where H:Hasher, Self:Sized,

Feeds a slice of this type into the givenHasher.Read more
Source§

implPartialEq forModule

Source§

fneq(&self, other: &Self) ->bool

Tests forself andother values to be equal, and is used by==.
1.0.0 ·Source§

fnne(&self, other:&Rhs) ->bool

Tests for!=. The default implementation is almost always sufficient,and should not be overridden without very good reason.
Source§

implTrace forModule

Source§

unsafe fntrace(&self, tracer: &mut Tracer)

Marks all containedGcs.Read more
Source§

unsafe fntrace_non_roots(&self)

Trace handles located in GC heap, and mark them as non root.Read more
Source§

fnrun_finalizer(&self)

RunsFinalize::finalize on this object and allcontained subobjects.
Source§

implEq forModule

Auto Trait Implementations§

§

implFreeze forModule

§

impl !RefUnwindSafe forModule

§

impl !Send forModule

§

impl !Sync forModule

§

implUnpin forModule

§

impl !UnwindSafe forModule

Blanket Implementations§

Source§

impl<T>Any for T
where T: 'static + ?Sized,

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

impl<T>Borrow<T> for T
where T: ?Sized,

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

impl<T>BorrowMut<T> for T
where T: ?Sized,

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>Conv for T

Source§

fnconv<T>(self) -> T
where Self:Into<T>,

Convertsself intoT usingInto<T>.Read more
Source§

impl<Q, K>Equivalent<K> for Q
where Q:Eq + ?Sized, K:Borrow<Q> + ?Sized,

Source§

fnequivalent(&self, key:&K) ->bool

Compare self tokey and returntrue if they are equal.
Source§

impl<Q, K>Equivalent<K> for Q
where Q:Eq + ?Sized, K:Borrow<Q> + ?Sized,

Source§

fnequivalent(&self, key:&K) ->bool

Checks if this value is equivalent to the given key.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U>Into<U> for T
where U:From<T>,

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

impl<T>IntoEither for T

Source§

fninto_either(self, into_left:bool) ->Either<Self, Self>

Convertsself into aLeft variant ofEither<Self, Self>ifinto_left istrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read more
Source§

fninto_either_with<F>(self, into_left: F) ->Either<Self, Self>
where F:FnOnce(&Self) ->bool,

Convertsself into aLeft variant ofEither<Self, Self>ifinto_left(&self) returnstrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read more
Source§

impl<T>Pipe for T
where T: ?Sized,

Source§

fnpipe<R>(self, func: implFnOnce(Self) -> R) -> R
where Self:Sized,

Pipes by value. This is generally the method you want to use.Read more
Source§

fnpipe_ref<'a, R>(&'a self, func: implFnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrowsself and passes that borrow into the pipe function.Read more
Source§

fnpipe_ref_mut<'a, R>(&'a mut self, func: implFnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrowsself and passes that borrow into the pipe function.Read more
Source§

fnpipe_borrow<'a, B, R>(&'a self, func: implFnOnce(&'a B) -> R) -> R
where Self:Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrowsself, then passesself.borrow() into the pipe function.Read more
Source§

fnpipe_borrow_mut<'a, B, R>( &'a mut self, func: implFnOnce(&'a mut B) -> R,) -> R
where Self:BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrowsself, then passesself.borrow_mut() into the pipefunction.Read more
Source§

fnpipe_as_ref<'a, U, R>(&'a self, func: implFnOnce(&'a U) -> R) -> R
where Self:AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrowsself, then passesself.as_ref() into the pipe function.
Source§

fnpipe_as_mut<'a, U, R>(&'a mut self, func: implFnOnce(&'a mut U) -> R) -> R
where Self:AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrowsself, then passesself.as_mut() into the pipefunction.
Source§

fnpipe_deref<'a, T, R>(&'a self, func: implFnOnce(&'a T) -> R) -> R
where Self:Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrowsself, then passesself.deref() into the pipe function.
Source§

fnpipe_deref_mut<'a, T, R>( &'a mut self, func: implFnOnce(&'a mut T) -> R,) -> R
where Self:DerefMut<Target = T> +Deref, T: 'a + ?Sized, R: 'a,

Mutably borrowsself, then passesself.deref_mut() into the pipefunction.
Source§

impl<T>Tap for T

Source§

fntap(self, func: implFnOnce(&Self)) -> Self

Immutable access to a value.Read more
Source§

fntap_mut(self, func: implFnOnce(&mut Self)) -> Self

Mutable access to a value.Read more
Source§

fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
where Self:Borrow<B>, B: ?Sized,

Immutable access to theBorrow<B> of a value.Read more
Source§

fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
where Self:BorrowMut<B>, B: ?Sized,

Mutable access to theBorrowMut<B> of a value.Read more
Source§

fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
where Self:AsRef<R>, R: ?Sized,

Immutable access to theAsRef<R> view of a value.Read more
Source§

fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
where Self:AsMut<R>, R: ?Sized,

Mutable access to theAsMut<R> view of a value.Read more
Source§

fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
where Self:Deref<Target = T>, T: ?Sized,

Immutable access to theDeref::Target of a value.Read more
Source§

fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
where Self:DerefMut<Target = T> +Deref, T: ?Sized,

Mutable access to theDeref::Target of a value.Read more
Source§

fntap_dbg(self, func: implFnOnce(&Self)) -> Self

Calls.tap() only in debug builds, and is erased in release builds.
Source§

fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self

Calls.tap_mut() only in debug builds, and is erased in releasebuilds.
Source§

fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
where Self:Borrow<B>, B: ?Sized,

Calls.tap_borrow() only in debug builds, and is erased in releasebuilds.
Source§

fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
where Self:BorrowMut<B>, B: ?Sized,

Calls.tap_borrow_mut() only in debug builds, and is erased in releasebuilds.
Source§

fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
where Self:AsRef<R>, R: ?Sized,

Calls.tap_ref() only in debug builds, and is erased in releasebuilds.
Source§

fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
where Self:AsMut<R>, R: ?Sized,

Calls.tap_ref_mut() only in debug builds, and is erased in releasebuilds.
Source§

fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
where Self:Deref<Target = T>, T: ?Sized,

Calls.tap_deref() only in debug builds, and is erased in releasebuilds.
Source§

fntap_deref_mut_dbg<T>(self, func: implFnOnce(&mut T)) -> Self
where Self:DerefMut<Target = T> +Deref, T: ?Sized,

Calls.tap_deref_mut() only in debug builds, and is erased in releasebuilds.
Source§

impl<T>ToOwned for T
where T:Clone,

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning.Read more
Source§

fnclone_into(&self, target:&mut T)

Uses borrowed data to replace owned data, usually by cloning.Read more
Source§

impl<T>TryConv for T

Source§

fntry_conv<T>(self) ->Result<T, Self::Error>
where Self:TryInto<T>,

Attempts to convertself intoT usingTryInto<T>.Read more
Source§

impl<T, U>TryFrom<U> for T
where U:Into<T>,

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U>TryInto<U> for T
where U:TryFrom<T>,

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T>VZip<V> for T
where V:MultiLane<T>,

Source§

fnvzip(self) -> V

Source§

impl<T>ErasedDestructor for T
where T: 'static,


[8]ページ先頭

©2009-2025 Movatter.jp