Struct sway_core::semantic_analysis::namespace::Module
source · pub struct Module {
pub name: Option<Ident>,
pub span: Option<Span>,
pub is_external: bool,
/* private fields */
}
Expand description
A single Module
within a Sway project.
A Module
is most commonly associated with an individual file of Sway code, e.g. a top-level
script/predicate/contract file or some library dependency whether introduced via mod
or the
[dependencies]
table of a forc
manifest.
A Module
contains a set of all items that exist within the lexical scope via declaration or
importing, along with a map of each of its submodules.
Fields§
§name: Option<Ident>
Name of the module, package name for root module, module name for other modules.
Module name used is the same as declared in mod name;
.
span: Option<Span>
Empty span at the beginning of the file implementing the module
is_external: bool
Indicates whether the module is external to the current package. External modules are
imported in the Forc.toml
file.
Implementations§
source§impl Module
impl Module
sourcepub fn default_with_contract_id(
engines: Engines<'_>,
name: Option<Ident>,
contract_id_value: String
) -> Result<Self, Vec1<CompileError>>
pub fn default_with_contract_id( engines: Engines<'_>, name: Option<Ident>, contract_id_value: String ) -> Result<Self, Vec1<CompileError>>
contract_id_value
is injected here via forc-pkg when producing the dependency_namespace
for a contract which has tests enabled.
This allows us to provide a contract’s CONTRACT_ID
constant to its own unit tests.
This will eventually be refactored out of sway-core
in favor of creating temporary package dependencies for providing these
CONTRACT_ID
-containing modules: https://github.com/FuelLabs/sway/issues/3077
sourcepub fn submodules(&self) -> &OrdMap<String, Module>
pub fn submodules(&self) -> &OrdMap<String, Module>
Immutable access to this module’s submodules.
sourcepub fn insert_submodule(&mut self, name: String, submodule: Module)
pub fn insert_submodule(&mut self, name: String, submodule: Module)
Insert a submodule into this Module
.
sourcepub fn submodule(&self, path: &Path) -> Option<&Module>
pub fn submodule(&self, path: &Path) -> Option<&Module>
Lookup the submodule at the given path.
sourcepub fn submodule_mut(&mut self, path: &Path) -> Option<&mut Module>
pub fn submodule_mut(&mut self, path: &Path) -> Option<&mut Module>
Unique access to the submodule at the given path.
sourcepub fn star_import_with_reexports(
&mut self,
src: &Path,
dst: &Path,
engines: Engines<'_>
) -> CompileResult<()>
pub fn star_import_with_reexports( &mut self, src: &Path, dst: &Path, engines: Engines<'_> ) -> CompileResult<()>
Given a path to a src
module, create synonyms to every symbol in that module to the given
dst
module.
This is used when an import path contains an asterisk.
Paths are assumed to be relative to self
.
Methods from Deref<Target = Items>§
pub fn apply_storage_load( &self, engines: Engines<'_>, fields: Vec<Ident>, storage_fields: &[TyStorageField] ) -> CompileResult<(TyStorageAccess, TypeId)>
pub fn set_storage_declaration( &mut self, decl_ref: DeclRefStorage ) -> CompileResult<()>
pub fn get_all_declared_symbols(&self) -> impl Iterator<Item = &Ident>
pub fn get_items_for_type( &self, engines: Engines<'_>, type_id: TypeId ) -> Vec<TyTraitItem>
pub fn get_methods_for_type( &self, engines: Engines<'_>, type_id: TypeId ) -> Vec<DeclRefFunction>
pub fn get_declared_storage( &self, decl_engine: &DeclEngine ) -> Option<TyStorageDecl>
Trait Implementations§
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> AnyDebug for Twhere
T: Any + Debug,
impl<T> AnyDebug for Twhere T: Any + Debug,
source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
Any
.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.