pub struct Path {
qualifier: Vec<Identifier>,
identifier: Identifier,
is_absolute: bool,
absolute_path: Option<Vec<Symbol>>,
pub span: Span,
pub id: NodeID,
}Expand description
A Path in a program.
Fields§
§qualifier: Vec<Identifier>The qualifying namespace segments written by the user, excluding the item itself.
e.g., in foo::bar::baz, this would be [foo, bar].
identifier: IdentifierThe final item in the path, e.g., baz in foo::bar::baz.
is_absolute: boolIs this path an absolute path? e.g. ::foo::bar::baz.
absolute_path: Option<Vec<Symbol>>The fully resolved path. We may not know this until the pass PathResolution pass runs.
For path that refer to global items (structs, consts, functions), absolute_path is
guaranteed to be set after the pass PathResolution.
span: SpanA span locating where the path occurred in the source.
id: NodeIDThe ID of the node.
Implementations§
Source§impl Path
impl Path
Sourcepub fn new(
qualifier: Vec<Identifier>,
identifier: Identifier,
is_absolute: bool,
absolute_path: Option<Vec<Symbol>>,
span: Span,
id: NodeID,
) -> Self
pub fn new( qualifier: Vec<Identifier>, identifier: Identifier, is_absolute: bool, absolute_path: Option<Vec<Symbol>>, span: Span, id: NodeID, ) -> Self
Creates a new Path from the given components.
qualifier: The namespace segments (e.g.,foo::barinfoo::bar::baz).identifier: The final item in the path (e.g.,baz).is_absolute: Whether the path is absolute (starts with::).absolute_path: Optionally, the fully resolved symbolic path.span: The source code span for this path.id: The node ID.
Sourcepub fn identifier(&self) -> Identifier
pub fn identifier(&self) -> Identifier
Returns the final identifier of the path (e.g., baz in foo::bar::baz).
Sourcepub fn qualifier(&self) -> &[Identifier]
pub fn qualifier(&self) -> &[Identifier]
Returns a slice of the qualifier segments (e.g., [foo, bar] in foo::bar::baz).
Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
Returns true if the path is absolute (i.e., starts with ::).
Sourcepub fn as_symbols(&self) -> Vec<Symbol>
pub fn as_symbols(&self) -> Vec<Symbol>
Returns a Vec<Symbol> representing the full symbolic path:
the qualifier segments followed by the final identifier.
Note: this refers to the user path which is not necessarily the absolute path.
Sourcepub fn try_absolute_path(&self) -> Option<Vec<Symbol>>
pub fn try_absolute_path(&self) -> Option<Vec<Symbol>>
Returns an optional vector of Symbols representing the resolved absolute path,
or None if resolution has not yet occurred.
Sourcepub fn absolute_path(&self) -> Vec<Symbol>
pub fn absolute_path(&self) -> Vec<Symbol>
Returns a vector of Symbols representing the resolved absolute path.
If the path is not an absolute path, this method panics if the absolute path has not been resolved yet. For relative paths, this is expected to be called only after path resolution has occurred.
Sourcepub fn into_absolute(self) -> Self
pub fn into_absolute(self) -> Self
Converts this Path into an absolute path by setting its is_absolute flag to true.
This does not alter the qualifier or identifier, nor does it compute or modify
the resolved absolute_path.
Sourcepub fn with_updated_last_symbol(self, new_symbol: Symbol) -> Self
pub fn with_updated_last_symbol(self, new_symbol: Symbol) -> Self
Returns a new Path instance with the last segment’s Symbol and the last symbol
in the absolute_path (if present) replaced with new_symbol.
Other fields remain unchanged.
Sourcepub fn with_absolute_path(self, absolute_path: Option<Vec<Symbol>>) -> Self
pub fn with_absolute_path(self, absolute_path: Option<Vec<Symbol>>) -> Self
Sets self.absolute_path to absolute_path
Sourcepub fn with_module_prefix(self, module_prefix: &[Symbol]) -> Self
pub fn with_module_prefix(self, module_prefix: &[Symbol]) -> Self
Sets the absolute_path by prepending the given module_prefix to the path’s
own qualifier and identifier. Returns the updated Path.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Path
impl<'de> Deserialize<'de> for Path
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>,
Source§impl From<Identifier> for Path
impl From<Identifier> for Path
Source§fn from(value: Identifier) -> Self
fn from(value: Identifier) -> Self
Source§impl From<Path> for Expression
impl From<Path> for Expression
impl Eq for Path
impl StructuralPartialEq for Path
Auto Trait Implementations§
impl Freeze for Path
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnwindSafe for Path
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<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
fn take_from_value<D>(
value: &mut Value,
field: &str,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToSmolStr for T
impl<T> ToSmolStr for T
fn to_smolstr(&self) -> SmolStr
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.