pub struct ModuleId(pub String);Expand description
A unique, deterministic identifier for a module derived from its path relative to the project root.
The identifier is a "::" -separated string that mirrors the
directory structure of the source tree.
§Examples
| Source file (relative) | ModuleId value |
|---|---|
main.cjcl | "main" |
math.cjcl | "math" |
math/linalg.cjcl | "math::linalg" |
math/linalg/mod.cjcl | "math::linalg" |
The inner String is public so that callers can inspect the raw
identifier when necessary, but prefer using the provided methods
(from_relative_path,
from_import_path,
symbol_prefix) for construction and
formatting.
Tuple Fields§
§0: StringImplementations§
Source§impl ModuleId
impl ModuleId
Sourcepub fn from_relative_path(path: &Path) -> Self
pub fn from_relative_path(path: &Path) -> Self
Create a ModuleId from a filesystem path relative to the project root.
Strip the file extension and convert path separators to "::".
§Arguments
path- A path relative to the project root (e.g.,math/linalg.cjcl).
§Returns
A ModuleId whose inner string is the "::" -joined stem
(e.g., "math::linalg").
§Examples
let id = ModuleId::from_relative_path(Path::new("math/linalg.cjcl"));
assert_eq!(id.0, "math::linalg");Sourcepub fn from_import_path(segments: &[String]) -> Self
pub fn from_import_path(segments: &[String]) -> Self
Convert an import-path segment list into a ModuleId.
The segments are joined with "::" to form the identifier string.
§Arguments
segments- The import path segments (e.g.,["math", "linalg"]).
§Returns
A ModuleId whose inner string is "math::linalg".
§Examples
let id = ModuleId::from_import_path(&["math".into(), "linalg".into()]);
assert_eq!(id.0, "math::linalg");Sourcepub fn symbol_prefix(&self) -> String
pub fn symbol_prefix(&self) -> String
Return the mangled prefix used for symbols defined in this module.
The entry module ("main" or empty) returns an empty string so
that top-level symbols keep their original names. All other
modules return "<module_id>::".
§Returns
An empty String for the entry module, or the module path
followed by "::" for all other modules.
§Examples
assert_eq!(ModuleId("main".into()).symbol_prefix(), "");
assert_eq!(ModuleId("math".into()).symbol_prefix(), "math::");
assert_eq!(ModuleId("math::linalg".into()).symbol_prefix(), "math::linalg::");