Skip to main content

Module

Struct Module 

Source
pub struct Module {
    pub name: String,
    pub path: Vec<String>,
    pub decls: Vec<Decl>,
    pub imports: Vec<String>,
    pub exports: Vec<String>,
    pub import_specs: Vec<ImportSpec>,
    pub export_spec: Option<ExportSpec>,
    pub namespaces: Vec<NamespaceScope>,
    pub opens: Vec<OpenDirective>,
    pub visibility_map: HashMap<String, Visibility>,
    pub config: ModuleConfig,
}
Expand description

A module containing declarations.

Fields§

§name: String

Module name

§path: Vec<String>

Module path

§decls: Vec<Decl>

Declarations in this module

§imports: Vec<String>

Imported modules

§exports: Vec<String>

Exported names

§import_specs: Vec<ImportSpec>

Import specifications

§export_spec: Option<ExportSpec>

Export specification

§namespaces: Vec<NamespaceScope>

Namespace scopes

§opens: Vec<OpenDirective>

Open directives

§visibility_map: HashMap<String, Visibility>

Name visibility information

§config: ModuleConfig

Module configuration

Implementations§

Source§

impl Module

Source

pub fn new(name: String) -> Self

Create a new module.

Source

pub fn with_config(name: String, config: ModuleConfig) -> Self

Create a module with configuration.

Source

pub fn add_decl(&mut self, decl: Decl)

Add a declaration to this module.

Source

pub fn add_import(&mut self, module: String)

Add an import.

Source

pub fn add_export(&mut self, name: String)

Add an export.

Source

pub fn full_path(&self) -> String

Get the full path of this module.

Source

pub fn resolve_name(&self, name: &str) -> ResolvedName

Resolve a name within this module.

Checks local declarations first, then imported modules via import specs, then namespace aliases.

Source

pub fn visible_names(&self) -> Vec<String>

Get all visible names (declared + imported).

Source

pub fn exported_names(&self) -> Vec<String>

Get names visible to importers of this module.

Source

pub fn add_namespace(&mut self, ns: NamespaceScope)

Add a namespace scope.

Source

pub fn with_import_spec(&mut self, spec: ImportSpec)

Apply an import specification.

Source

pub fn set_visibility(&mut self, name: String, visibility: Visibility)

Set visibility for a name.

Source

pub fn get_visibility(&self, name: &str) -> Visibility

Get visibility of a name.

Source

pub fn add_open(&mut self, module: String, scoped: bool)

Add an open directive.

Source

pub fn get_opens(&self) -> Vec<String>

Get all open modules.

Source

pub fn resolve_with_opens(&self, name: &str) -> ResolvedName

Resolve a name considering all open modules and imports.

Source

pub fn all_visible_names(&self) -> Vec<NameVisibility>

Get all visible names including from opens.

Source

pub fn is_accessible(&self, name: &str, from_same_module: bool) -> bool

Check if a name is accessible with given visibility context.

Source

pub fn get_dependencies(&self) -> HashSet<String>

Get all direct dependencies (imports and opens).

Source

pub fn imports_module(&self, other: &str) -> bool

Check if this module directly imports another.

Source

pub fn resolve_selective_import( &self, _module: &str, selected: &[String], ) -> Vec<String>

Resolve a selective import to actual names.

Source

pub fn get_hidden_names(&self, module: &str) -> Vec<String>

Get all names hidden by a hiding import.

Source

pub fn create_nested_namespace(&mut self, name: String, parent: NamespaceScope)

Create a nested namespace scope.

Source

pub fn lookup_in_namespaces(&self, name: &str) -> Option<String>

Look up a name in namespace hierarchy.

Source

pub fn namespace_names(&self, ns_name: &str) -> Vec<String>

Get all names in a specific namespace.

Source

pub fn set_default_visibility(&mut self, visibility: Visibility)

Set default visibility for all names (for private_by_default config).

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

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

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.