pub struct NamespaceScope { /* private fields */ }Expand description
Represents the scope for resolving PHP names, holding the current namespace and any ‘use’ aliases defined within it.
This struct keeps track of the current namespace and the different types
of aliases (use, use function, use const). It provides methods to
manage aliases and resolve names according to PHP’s rules (handling FQNs,
aliases, the namespace keyword, and namespace relativity).
Aliases are stored case-insensitively (keys in the maps are lowercase) but resolve to the original case-sensitive FQN.
Implementations§
Source§impl NamespaceScope
impl NamespaceScope
Sourcepub fn new(namespace_name: Option<String>) -> Self
pub fn new(namespace_name: Option<String>) -> Self
Creates a new, empty scope, optionally associated with a namespace.
Sourcepub fn for_namespace(namespace: impl Into<String>) -> Self
pub fn for_namespace(namespace: impl Into<String>) -> Self
Creates a new, empty scope representing the given namespace.
Sourcepub fn has_aliases(&self) -> bool
pub fn has_aliases(&self) -> bool
Checks if any aliases have been defined in this scope.
Sourcepub fn namespace_name(&self) -> Option<&str>
pub fn namespace_name(&self) -> Option<&str>
Returns the name of the current namespace, if this scope represents one.
Sourcepub fn default_aliases(&self) -> &HashMap<String, String>
pub fn default_aliases(&self) -> &HashMap<String, String>
Returns a reference to the map of default (class/namespace) aliases.
Sourcepub fn function_aliases(&self) -> &HashMap<String, String>
pub fn function_aliases(&self) -> &HashMap<String, String>
Returns a reference to the map of function aliases.
Sourcepub fn constant_aliases(&self) -> &HashMap<String, String>
pub fn constant_aliases(&self) -> &HashMap<String, String>
Returns a reference to the map of constant aliases.
Sourcepub fn populate_from_use(&mut self, use: &Use<'_>)
pub fn populate_from_use(&mut self, use: &Use<'_>)
Populates the scope’s alias tables based on a PHP use statement AST node.
This method processes the different forms of use statements (simple, function/const,
grouped) and registers the corresponding aliases within this NamespaceScope.
It iterates through the items declared in the use statement and calls self.add
for each one with the appropriate kind, fully qualified name, and optional alias.
§Arguments
interner- A string interner used to resolve identifiers/names from the AST nodes into actual string (&str) representations.r#use- A reference to theUseAST node representing theusestatement. (Parameter is namedr#usebecauseuseis a Rust keyword).
Sourcepub fn add(
&mut self,
kind: NameKind,
name: impl AsRef<str>,
alias: &Option<impl AsRef<str>>,
)
pub fn add( &mut self, kind: NameKind, name: impl AsRef<str>, alias: &Option<impl AsRef<str>>, )
Adds a new alias based on a ‘use’ statement to this scope.
§Arguments
kind- The type of alias (NameKind::Default,NameKind::Function,NameKind::Constant).name- The fully qualified name being imported (e.g., “App\Models\User”).alias- An optional explicit alias name (e.g., “UserModel”). IfNone, the alias is derived from the last part of thename(e.g., “User” from “App\Models\User”).
The alias name (explicit or derived) is stored lowercase as the key.
Sourcepub fn qualify_name(&self, name: impl AsRef<str>) -> String
pub fn qualify_name(&self, name: impl AsRef<str>) -> String
Qualifies a simple name by prepending the current namespace, if applicable.
This method is intended for simple names (containing no \) that are
not explicitly aliased or handled by \ or namespace\ prefixes.
If the current scope has a non-empty namespace name, it will be prepended.
Otherwise, the original name is returned.
§Arguments
name- The simple name to qualify (e.g., “User”).
§Returns
The qualified name (e.g., “App\Models\User”) or the original name if in the global scope, the namespace is empty, or the input name was not simple.
Sourcepub fn resolve_str<'a>(
&self,
kind: NameKind,
name_ref: &'a str,
) -> (Cow<'a, str>, bool)
pub fn resolve_str<'a>( &self, kind: NameKind, name_ref: &'a str, ) -> (Cow<'a, str>, bool)
non-generic version of resolve that takes a string slice.
Sourcepub fn resolve_alias(
&self,
kind: NameKind,
name: impl AsRef<str>,
) -> Option<String>
pub fn resolve_alias( &self, kind: NameKind, name: impl AsRef<str>, ) -> Option<String>
Attempts to resolve a name using only explicit aliases and constructs.
Does not attempt to qualify simple names relative to the current namespace if they aren’t aliased.
§Arguments
kind- The context (Default,Function,Constant).name- The name string to resolve.
§Returns
Some(String)containing the resolved FQN if an explicit rule applies.Noneif no explicit rule resolves the name.
Trait Implementations§
Source§impl Clone for NamespaceScope
impl Clone for NamespaceScope
Source§fn clone(&self) -> NamespaceScope
fn clone(&self) -> NamespaceScope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NamespaceScope
impl Debug for NamespaceScope
Source§impl Default for NamespaceScope
impl Default for NamespaceScope
Source§fn default() -> NamespaceScope
fn default() -> NamespaceScope
Source§impl<'de> Deserialize<'de> for NamespaceScope
impl<'de> Deserialize<'de> for NamespaceScope
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 PartialEq for NamespaceScope
impl PartialEq for NamespaceScope
Source§impl Serialize for NamespaceScope
impl Serialize for NamespaceScope
impl Eq for NamespaceScope
impl StructuralPartialEq for NamespaceScope
Auto Trait Implementations§
impl Freeze for NamespaceScope
impl RefUnwindSafe for NamespaceScope
impl Send for NamespaceScope
impl Sync for NamespaceScope
impl Unpin for NamespaceScope
impl UnsafeUnpin for NamespaceScope
impl UnwindSafe for NamespaceScope
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);