pub struct QualName { /* private fields */ }Expand description
Qualified name: a declaration, named by the package and the module that declare it.
The module half can be thought of as a non-empty vector: My.Module.function is a vec of
My and Module, plus the always non-empty function.
§Why the package is part of it
A module’s name is unique within its package and not across a build: a package may
hold its own Size beside a dependency’s, which it reaches as AcmeWidgets.Size
(What a package boundary cannot
rename). Both
declare Size.Size, and only the package tells the two apart. With it, every
QualName names one declaration on its own: once we are given a QualName, no further
resolution is necessary, and two QualNames are equal exactly when they name the same
declaration. Every map the phases after canonicalization key by one — the typer’s
unions and constructors, a scalar’s identity (Scalar::declares) — relies on that.
The package is part of the identity and of nothing a source file writes:
to_name leaves it out, since acme-widgets is a spelling no
Zelkova source contains.
Implementations§
Source§impl QualName
impl QualName
Sourcepub fn parse<S: Into<String>>(package: PackageName, s: S) -> Option<QualName>
pub fn parse<S: Into<String>>(package: PackageName, s: S) -> Option<QualName>
The name s spells, declared in package: Basics.Int is the module Basics
and the name Int. None when s has no module half.
Sourcepub fn from_strs<S1, S2, I>(
package: PackageName,
name: S1,
prefix: I,
) -> Option<QualName>
pub fn from_strs<S1, S2, I>( package: PackageName, name: S1, prefix: I, ) -> Option<QualName>
The name name, declared in package by the module whose segments prefix
yields. None when prefix yields nothing.
Sourcepub fn in_module(package: PackageName, module: &str, name: &str) -> QualName
pub fn in_module(package: PackageName, module: &str, name: &str) -> QualName
The name name, as declared by module of package.
module is written out with its dots, the way a module header writes it, and
is split back into segments here; name is kept whole. It is how
ModuleName::qualify_name names a declaration
of a module it holds, and how a name the compiler knows without reading it from a
source file — a scalar — becomes a QualName.
module must be a non-empty module path. That is a precondition on the
caller, not a check: this returns a QualName rather than an Option because
the two halves arrive separately and there is no text to go looking for a module
in, which is what keeps the scalar names off any unwrap path. It is not a
claim that every input is well formed — in_module(package, "", "Bool") builds a
name that renders as .Bool and that
Scalar::declares recognises for nothing,
where QualName::parse and QualName::from_strs would both have returned
None. Every caller passes a module path it holds.
Sourcepub fn sibling(&self, name: &Name) -> QualName
pub fn sibling(&self, name: &Name) -> QualName
The name name, declared by the same module of the same package as this one.
It is how a union’s constructors are named from the union: a constructor is declared by the module that declares the type it builds.
Sourcepub fn package(&self) -> &PackageName
pub fn package(&self) -> &PackageName
The package that declares this name.
Sourcepub fn to_name(&self) -> Name
pub fn to_name(&self) -> Name
The module and the name, written out with dots — Size.Size — and without the
package, which no source spells.
pub fn unqualified_name(&self) -> Name
Sourcepub fn module_name(&self) -> Name
pub fn module_name(&self) -> Name
The module half, written out with its dots — My.App of My.App.function.
The counterpart of QualName::unqualified_name; the two halves rejoined are
QualName::to_name.
Trait Implementations§
impl Eq for QualName
impl StructuralPartialEq for QualName
Auto Trait Implementations§
impl Freeze for QualName
impl RefUnwindSafe for QualName
impl Send for QualName
impl Sync for QualName
impl Unpin for QualName
impl UnsafeUnpin for QualName
impl UnwindSafe for QualName
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.