Skip to main content

QualName

Struct QualName 

Source
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

Source

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.

Source

pub fn from_strs<S1, S2, I>( package: PackageName, name: S1, prefix: I, ) -> Option<QualName>
where S1: Into<String>, S2: Into<String>, I: Iterator<Item = S2>,

The name name, declared in package by the module whose segments prefix yields. None when prefix yields nothing.

Source

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.

Source

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.

Source

pub fn package(&self) -> &PackageName

The package that declares this name.

Source

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.

Source

pub fn unqualified_name(&self) -> Name

Source

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§

Source§

impl Clone for QualName

Source§

fn clone(&self) -> QualName

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for QualName

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for QualName

Source§

impl Hash for QualName

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for QualName

Source§

fn eq(&self, other: &QualName) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for QualName

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.