pub struct ImportRegistry {
pub config_imports: HashMap<String, String>,
/* private fields */
}Expand description
Unified import registry. Built during IR lowering, used throughout expansion.
All insertions are idempotent — duplicates are impossible by design. The registry has three sections:
- Source imports — pre-populated from the user’s AST during lowering. Read-only after creation.
- Config imports — from
macroforge.config.tsimport statements. Name → module. - Generated imports — accumulated during macro expansion via
request_*methods.
Fields§
§config_imports: HashMap<String, String>Config file imports (macroforge.config.ts import statements). Name → module.
Implementations§
Source§impl ImportRegistry
impl ImportRegistry
Sourcepub fn from_module(module: &Module, source: &str) -> Self
pub fn from_module(module: &Module, source: &str) -> Self
Build from AST — extracts all import declarations from the module.
Called during IR lowering in prepare_expansion_context.
Sourcepub fn is_available(&self, name: &str) -> bool
pub fn is_available(&self, name: &str) -> bool
Check if an identifier is available (in source OR already generated).
Sourcepub fn is_type_only(&self, name: &str) -> bool
pub fn is_type_only(&self, name: &str) -> bool
Check if a source import is type-only. Returns false if the import is not found.
Sourcepub fn get_source(&self, name: &str) -> Option<&str>
pub fn get_source(&self, name: &str) -> Option<&str>
Get import module for a source import.
Sourcepub fn resolve_alias(&self, name: &str) -> Option<&str>
pub fn resolve_alias(&self, name: &str) -> Option<&str>
Resolve alias to original name.
For import { Option as EffectOption }, resolve_alias("EffectOption") → Some("Option").
Sourcepub fn source_map(&self) -> &HashMap<String, SourceImport>
pub fn source_map(&self) -> &HashMap<String, SourceImport>
Get all source imports as a reference to the internal HashMap.
Sourcepub fn source_modules(&self) -> HashMap<String, String>
pub fn source_modules(&self) -> HashMap<String, String>
Get source imports as a flat name→module HashMap (for backward-compat callers).
Sourcepub fn aliases(&self) -> HashMap<String, String>
pub fn aliases(&self) -> HashMap<String, String>
Get import aliases as a flat local→original HashMap (for backward-compat callers).
Sourcepub fn source_import_entries(&self) -> Vec<SourceImportEntry>
pub fn source_import_entries(&self) -> Vec<SourceImportEntry>
Export source imports as serializable entries for cross-process transfer.
Sourcepub fn install_source_imports(&mut self, entries: Vec<SourceImportEntry>)
pub fn install_source_imports(&mut self, entries: Vec<SourceImportEntry>)
Install source imports from serializable entries (for external macro processes).
Sourcepub fn type_only_map(&self) -> HashMap<String, bool>
pub fn type_only_map(&self) -> HashMap<String, bool>
Get type-only tracking as a flat name→bool HashMap (for backward-compat callers).
Sourcepub fn request_import(
&mut self,
local_name: &str,
original_name: Option<&str>,
module: &str,
is_type_only: bool,
)
pub fn request_import( &mut self, local_name: &str, original_name: Option<&str>, module: &str, is_type_only: bool, )
General-purpose import request. Idempotent — skips if local_name already
exists in source or generated imports.
This is the method TsStream import helpers delegate to.
Sourcepub fn request_namespace_import(
&mut self,
namespace: &str,
module: &str,
alias: &str,
)
pub fn request_namespace_import( &mut self, namespace: &str, module: &str, alias: &str, )
Request a namespace import (e.g., import { DateTime as __mf_DateTime } from "effect").
No-op if namespace is already a value import in source.
No-op if alias is already in generated.
Sourcepub fn request_type_import(&mut self, name: &str, module: &str)
pub fn request_type_import(&mut self, name: &str, module: &str)
Request a type-only import (e.g., import type { Utc } from "effect/DateTime").
No-op if name is already in source or generated.
Rejects dotted names (logs warning, returns early).
Sourcepub fn generated_imports(&self) -> impl Iterator<Item = &GeneratedImport>
pub fn generated_imports(&self) -> impl Iterator<Item = &GeneratedImport>
Get an iterator over generated imports.
Sourcepub fn take_generated_imports(&mut self) -> Vec<GeneratedImport>
pub fn take_generated_imports(&mut self) -> Vec<GeneratedImport>
Take a snapshot of generated imports and clear them from the registry.
Used by TsStream::into_result() to capture imports into MacroResult
so they survive serialization across process boundaries.
Sourcepub fn merge_imports(&mut self, imports: Vec<GeneratedImport>)
pub fn merge_imports(&mut self, imports: Vec<GeneratedImport>)
Merge a list of generated imports back into the registry.
Used to restore imports from a MacroResult (e.g., from an external macro).
Sourcepub fn emit_generated_imports(&self) -> String
pub fn emit_generated_imports(&self) -> String
Format all generated imports as TypeScript import lines.
Trait Implementations§
Source§impl Clone for ImportRegistry
impl Clone for ImportRegistry
Source§fn clone(&self) -> ImportRegistry
fn clone(&self) -> ImportRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImportRegistry
impl Debug for ImportRegistry
Source§impl Default for ImportRegistry
impl Default for ImportRegistry
Source§impl<'de> Deserialize<'de> for ImportRegistry
impl<'de> Deserialize<'de> for ImportRegistry
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>,
Auto Trait Implementations§
impl Freeze for ImportRegistry
impl RefUnwindSafe for ImportRegistry
impl Send for ImportRegistry
impl Sync for ImportRegistry
impl Unpin for ImportRegistry
impl UnsafeUnpin for ImportRegistry
impl UnwindSafe for ImportRegistry
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ImplicitClone for Twhere
T: Clone,
impl<T> ImplicitClone for Twhere
T: Clone,
fn clone_quote_var(&self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more