pub struct Namespace<T = NotFinal> { /* private fields */ }Expand description
A Namespace is a collection of named Shapes, which can be used to
give meaning to (resolve) ShapeCase::Name references.
The Namespace<NotFinal> and Namespace<Final> types represent the two
stages of a namespace’s lifecycle: before and after finalization. The
finalization process resolves all ShapeCase::Name references within the
shapes of the namespace, ensuring every name has a stable weak reference
back to the named shape’s ShapeCase.
We implement Clone for Namespace manually below, always returning a
Namespace<NotFinal>.
Implementations§
Source§impl<T> Namespace<T>
impl<T> Namespace<T>
Sourcepub fn has(&self, name: &str) -> bool
pub fn has(&self, name: &str) -> bool
Any Namespace (Namespace<NotFinal> or Namespace<Final>) can tell
you whether a given name is bound, using the has method.
Sourcepub fn names(&self) -> impl Iterator<Item = &str> + '_
pub fn names(&self) -> impl Iterator<Item = &str> + '_
Returns an iterator over the names in the namespace.
Sourcepub fn merge<U>(&self, other: &Namespace<U>) -> Namespace<NotFinal>
pub fn merge<U>(&self, other: &Namespace<U>) -> Namespace<NotFinal>
Non-destructively merges two Namespaces (self and other)
together into a new Namespace. When there are collisions, Shapes
of the same name will be combined with Shape::all([self_shape, other_shape], []). The T and U types of self: &Namespace<T> and
other: &Namespace<U> are unrestricted and do not have to agree, though
the final merged result is always Namespace<NotFinal>.
Source§impl Namespace<NotFinal>
impl Namespace<NotFinal>
Sourcepub fn insert(&mut self, name: impl Into<String>, shape: Shape) -> Shape
pub fn insert(&mut self, name: impl Into<String>, shape: Shape) -> Shape
Mutably binds name to shape in the current Namespace, cloning
shape and recursively propagating names derived from name to all
nested child shapes. Since this cloning and name propagation generally
creates a new Shape, the insert method returns a clone of that
final Shape (inspectable with Shape::pretty_print_with_names).
Sourcepub fn finalize(&self) -> Namespace<Final>
pub fn finalize(&self) -> Namespace<Final>
Returns a finalized version of self, ensuring exclusive ownership of
all Ref<Shape> references, then binding all ShapeCase::Name
references nested within shapes owned by the new namespace.
Source§impl Namespace<Final>
impl Namespace<Final>
pub fn finalize(&self) -> Namespace<Final>
Sourcepub fn iter(&self) -> impl Iterator<Item = (String, Shape)> + '_
pub fn iter(&self) -> impl Iterator<Item = (String, Shape)> + '_
Returns an iterator over the name-shape pairs in the finalized namespace.
Sourcepub fn get(&self, name: &str) -> Option<Shape>
pub fn get(&self, name: &str) -> Option<Shape>
You must have a finalized Namespace<Final> to use the get method
to look up shapes in the Namespace.
While Namespace<NotFinal> supports has and insert and other
Namespace-building methods, the Namespace has to be promoted to
Namespace<Final> before you can actually look up any names.
Sourcepub fn get_or_none(&self, name: &str) -> Shape
pub fn get_or_none(&self, name: &str) -> Shape
In case self.get returns a Rust None, this method returns a
Shape::none() that’s named with the given name.
Sourcepub fn get_or_unknown(&self, name: &str) -> Shape
pub fn get_or_unknown(&self, name: &str) -> Shape
In case self.get returns a Rust None, this method returns an Unknown
shape that’s named with the given name.
Trait Implementations§
impl<T: Eq> Eq for Namespace<T>
impl<T> StructuralPartialEq for Namespace<T>
Auto Trait Implementations§
impl<T> Freeze for Namespace<T>
impl<T> RefUnwindSafe for Namespace<T>where
T: RefUnwindSafe,
impl<T> Send for Namespace<T>where
T: Send,
impl<T> Sync for Namespace<T>where
T: Sync,
impl<T> Unpin for Namespace<T>where
T: Unpin,
impl<T> UnwindSafe for Namespace<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§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.§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<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§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();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§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();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§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();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§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();§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.§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);