Module

Trait Module 

Source
pub trait Module:
    Debug
    + Send
    + Sync
    + Any
    + AsAny
    + Identifiable
    + DependenciesBlock
    + Diagnosable
    + ModuleSourceMapConfig
    + SerializeDyn {
Show 31 methods // Required methods fn module_type(&self) -> &ModuleType; fn source_types(&self, module_graph: &ModuleGraph<'_>) -> &[SourceType]; fn source(&self) -> Option<&BoxSource>; fn readable_identifier(&self, _context: &Context) -> Cow<'_, str>; fn size( &self, source_type: Option<&SourceType>, compilation: Option<&Compilation>, ) -> f64; fn factory_meta(&self) -> Option<&FactoryMeta>; fn set_factory_meta(&mut self, factory_meta: FactoryMeta); fn build_info(&self) -> &BuildInfo; fn build_info_mut(&mut self) -> &mut BuildInfo; fn build_meta(&self) -> &BuildMeta; fn build_meta_mut(&mut self) -> &mut BuildMeta; fn code_generation<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _compilation: &'life1 Compilation, _runtime: Option<&'life2 RuntimeSpec>, _concatenation_scope: Option<ConcatenationScope>, ) -> Pin<Box<dyn Future<Output = Result<CodeGenerationResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn get_runtime_hash<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, compilation: &'life1 Compilation, runtime: Option<&'life2 RuntimeSpec>, ) -> Pin<Box<dyn Future<Output = Result<RspackHashDigest>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; // Provided methods fn build<'life0, 'life1, 'async_trait>( &'life0 mut self, _build_context: BuildContext, _compilation: Option<&'life1 Compilation>, ) -> Pin<Box<dyn Future<Output = Result<BuildResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn get_exports_argument(&self) -> ExportsArgument { ... } fn get_module_argument(&self) -> ModuleArgument { ... } fn get_exports_type( &self, module_graph: &ModuleGraph<'_>, module_graph_cache: &ModuleGraphCacheArtifact, strict: bool, ) -> ExportsType { ... } fn get_strict_esm_module(&self) -> bool { ... } fn name_for_condition(&self) -> Option<Box<str>> { ... } fn lib_ident(&self, _options: LibIdentOptions<'_>) -> Option<Cow<'_, str>> { ... } fn get_code_generation_dependencies(&self) -> Option<&[BoxModuleDependency]> { ... } fn get_presentational_dependencies( &self, ) -> Option<&[BoxDependencyTemplate]> { ... } fn get_concatenation_bailout_reason( &self, _mg: &ModuleGraph<'_>, _cg: &ChunkGraph, ) -> Option<Cow<'static, str>> { ... } fn get_resolve_options(&self) -> Option<Arc<Resolve>> { ... } fn get_context(&self) -> Option<Box<Context>> { ... } fn get_layer(&self) -> Option<&ModuleLayer> { ... } fn chunk_condition( &self, _chunk_key: &ChunkUkey, _compilation: &Compilation, ) -> Option<bool> { ... } fn get_side_effects_connection_state( &self, _module_graph: &ModuleGraph<'_>, _module_graph_cache: &ModuleGraphCacheArtifact, _module_chain: &mut IdentifierSet, _connection_state_cache: &mut IdentifierMap<ConnectionState>, ) -> ConnectionState { ... } fn need_build(&self, value_cache_version: &ValueCacheVersions) -> bool { ... } fn depends_on(&self, modified_file: &ArcPathSet) -> bool { ... } fn need_id(&self) -> bool { ... }
}

Required Methods§

Source

fn module_type(&self) -> &ModuleType

Defines what kind of module this is.

Source

fn source_types(&self, module_graph: &ModuleGraph<'_>) -> &[SourceType]

Defines what kind of code generation results this module can generate.

Source

fn source(&self) -> Option<&BoxSource>

The source of the module. This could be optional, modules like the NormalModule can have the corresponding source. However, modules that is created from “nowhere” (e.g. ExternalModule and MissingModule) does not have its source.

Source

fn readable_identifier(&self, _context: &Context) -> Cow<'_, str>

User readable identifier of the module.

Source

fn size( &self, source_type: Option<&SourceType>, compilation: Option<&Compilation>, ) -> f64

The size of the original source, which will used as a parameter for code-splitting. Only when calculating the size of the RuntimeModule is the Compilation depended on

Source

fn factory_meta(&self) -> Option<&FactoryMeta>

Source

fn set_factory_meta(&mut self, factory_meta: FactoryMeta)

Source

fn build_info(&self) -> &BuildInfo

Source

fn build_info_mut(&mut self) -> &mut BuildInfo

Source

fn build_meta(&self) -> &BuildMeta

Source

fn build_meta_mut(&mut self) -> &mut BuildMeta

Source

fn code_generation<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _compilation: &'life1 Compilation, _runtime: Option<&'life2 RuntimeSpec>, _concatenation_scope: Option<ConcatenationScope>, ) -> Pin<Box<dyn Future<Output = Result<CodeGenerationResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The actual code generation of the module, which will be called by the Compilation. The code generation result should not be cached as it is implemented elsewhere to provide a universal cache mechanism (time to invalidate cache, etc.)

Code generation will often iterate through every source_types given by the module to provide multiple code generation results for different source_types.

Source

fn get_runtime_hash<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, compilation: &'life1 Compilation, runtime: Option<&'life2 RuntimeSpec>, ) -> Pin<Box<dyn Future<Output = Result<RspackHashDigest>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update hash for cgm.hash (chunk graph module hash) Different cgm code generation result should have different cgm.hash, so this also accept compilation (mainly chunk graph) and runtime as args. (Difference with impl Hash for Module: this is just a part for calculating cgm.hash, not for Module itself)

Provided Methods§

Source

fn build<'life0, 'life1, 'async_trait>( &'life0 mut self, _build_context: BuildContext, _compilation: Option<&'life1 Compilation>, ) -> Pin<Box<dyn Future<Output = Result<BuildResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The actual build of the module, which will be called by the Compilation. Build can also returns the dependencies of the module, which will be used by the Compilation to build the dependency graph.

Source

fn get_exports_argument(&self) -> ExportsArgument

Source

fn get_module_argument(&self) -> ModuleArgument

Source

fn get_exports_type( &self, module_graph: &ModuleGraph<'_>, module_graph_cache: &ModuleGraphCacheArtifact, strict: bool, ) -> ExportsType

Source

fn get_strict_esm_module(&self) -> bool

Source

fn name_for_condition(&self) -> Option<Box<str>>

Name matched against bundle-splitting conditions.

Source

fn lib_ident(&self, _options: LibIdentOptions<'_>) -> Option<Cow<'_, str>>

Source

fn get_code_generation_dependencies(&self) -> Option<&[BoxModuleDependency]>

Code generation dependencies of the module, which means the code generation of this module depends on the code generation results of dependencies which are returned by this function. e.g Css module may rely on the code generation result of CssUrlDependency to re-direct the url of the referenced assets.

Source

fn get_presentational_dependencies(&self) -> Option<&[BoxDependencyTemplate]>

Source

fn get_concatenation_bailout_reason( &self, _mg: &ModuleGraph<'_>, _cg: &ChunkGraph, ) -> Option<Cow<'static, str>>

Source

fn get_resolve_options(&self) -> Option<Arc<Resolve>>

Resolve options matched by module rules. e.g javascript/esm may have special resolving options like fullySpecified. css and css/module may have special resolving options like preferRelative.

Source

fn get_context(&self) -> Option<Box<Context>>

Source

fn get_layer(&self) -> Option<&ModuleLayer>

Source

fn chunk_condition( &self, _chunk_key: &ChunkUkey, _compilation: &Compilation, ) -> Option<bool>

Source

fn get_side_effects_connection_state( &self, _module_graph: &ModuleGraph<'_>, _module_graph_cache: &ModuleGraphCacheArtifact, _module_chain: &mut IdentifierSet, _connection_state_cache: &mut IdentifierMap<ConnectionState>, ) -> ConnectionState

Source

fn need_build(&self, value_cache_version: &ValueCacheVersions) -> bool

Source

fn depends_on(&self, modified_file: &ArcPathSet) -> bool

Source

fn need_id(&self) -> bool

Implementations§

Source§

impl dyn Module

Source

pub fn downcast_ref<T: Module + Any>(&self) -> Option<&T>

Source

pub fn downcast_mut<T: Module + Any>(&mut self) -> Option<&mut T>

Source§

impl dyn Module

Source§

impl dyn Module

Source§

impl dyn Module

Source§

impl dyn Module

Source§

impl dyn Module

Source§

impl dyn Module

Trait Implementations§

Source§

impl ArchiveUnsized for dyn Module

Source§

type Archived = dyn DeserializeModule

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata(&self) -> ArchivedMetadata<Self>

Creates the archived version of the metadata for this value.
Source§

impl DeserializeDyn<dyn Module> for ArchivedConcatenatedModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl DeserializeDyn<dyn Module> for ArchivedContextModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl DeserializeDyn<dyn Module> for ArchivedExternalModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl DeserializeDyn<dyn Module> for ArchivedNormalModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl DeserializeDyn<dyn Module> for ArchivedRawModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl DeserializeDyn<dyn Module> for ArchivedSelfModule

Source§

fn deserialize_dyn( &self, deserializer: &mut Deserializer, out: *mut dyn Module, ) -> Result<(), DeserializeError>

Deserializes this value into the given out pointer.
Source§

fn deserialized_pointer_metadata(&self) -> DynMetadata<dyn Module>

Returns the pointer metadata for the deserialized form of this type.
Source§

impl Identifiable for Box<dyn Module>

Source§

fn identifier(&self) -> Identifier

Uniquely identify a module. If two modules share the same module identifier, then they are considered as the same module. e.g javascript/auto|<absolute-path>/index.js and javascript/auto|<absolute-path>/index.js are considered as the same.

Source§

impl LayoutRaw for dyn Module

Source§

fn layout_raw( metadata: <Self as Pointee>::Metadata, ) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl Pointee for dyn Module

Source§

type Metadata = DynMetadata<dyn Module>

The metadata type for pointers and references to this type.
Source§

impl SerializeUnsized<Strategy<Serializer<AlignedVec, ArenaHandle<'_>, Share>, SerializeError>> for dyn Module

Source§

fn serialize_unsized( &self, serializer: &mut Serializer<'_>, ) -> Result<usize, SerializeError>

Writes the object and returns the position of the archived type.

Implementors§