Skip to main content

Mapping

Struct Mapping 

Source
pub struct Mapping(/* private fields */);
Expand description

A YAML mapping (dictionary/object).

This is an ordered map that preserves insertion order, wrapping IndexMap<String, Value>. It provides a comprehensive API for working with YAML mappings.

§Examples

use noyalib::{Mapping, Value};

let mut map = Mapping::new();
map.insert("name", Value::from("test"));
map.insert("value", Value::from(42));

assert_eq!(map.len(), 2);
assert_eq!(map.get("name").unwrap().as_str(), Some("test"));

Implementations§

Source§

impl Mapping

Source

pub fn new() -> Self

Creates an empty mapping.

§Examples
use noyalib::Mapping;
let m = Mapping::new();
assert!(m.is_empty());
Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty mapping with the specified capacity.

Pre-allocates room for capacity entries to avoid rehashing during the first inserts.

§Examples
use noyalib::Mapping;
let m = Mapping::with_capacity(16);
assert!(m.capacity() >= 16);
Source

pub fn capacity(&self) -> usize

Returns the number of key-value pairs the mapping can hold without reallocating.

§Examples
use noyalib::Mapping;
let m = Mapping::with_capacity(8);
assert!(m.capacity() >= 8);
Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more key-value pairs.

§Examples
use noyalib::Mapping;
let mut m = Mapping::new();
m.reserve(64);
assert!(m.capacity() >= 64);
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the mapping as much as possible.

§Examples
use noyalib::Mapping;
let mut m = Mapping::with_capacity(64);
m.shrink_to_fit();
// capacity may now be 0 or any small implementation-defined value.
Source

pub fn len(&self) -> usize

Returns the number of key-value pairs in the mapping.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
assert_eq!(m.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if the mapping contains no key-value pairs.

§Examples
use noyalib::Mapping;
assert!(Mapping::new().is_empty());
Source

pub fn clear(&mut self)

Clears the mapping, removing all key-value pairs.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.clear();
assert!(m.is_empty());
Source

pub fn insert(&mut self, key: impl Into<String>, value: Value) -> Option<Value>

Inserts a key-value pair into the mapping.

If the mapping already had this key present, the value is updated, and the old value is returned.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
assert_eq!(m.insert("a", Value::from(1_i64)), None);
assert_eq!(m.insert("a", Value::from(2_i64)).and_then(|v| v.as_i64()), Some(1));
Source

pub fn contains_key(&self, key: &str) -> bool

Returns true if the mapping contains the specified key.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
assert!(m.contains_key("a"));
assert!(!m.contains_key("b"));
Source

pub fn get(&self, key: &str) -> Option<&Value>

Returns a reference to the value corresponding to the key.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
assert_eq!(m.get("a").and_then(Value::as_i64), Some(1));
assert!(m.get("b").is_none());
Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

Returns a mutable reference to the value corresponding to the key.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
if let Some(v) = m.get_mut("a") {
    *v = Value::from(2_i64);
}
assert_eq!(m.get("a").and_then(Value::as_i64), Some(2));
Source

pub fn get_index(&self, index: usize) -> Option<(&String, &Value)>

Returns a reference to the key-value pair at the given index.

Indexing follows insertion order (this is an IndexMap).

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("first", Value::from(1_i64));
m.insert("second", Value::from(2_i64));
assert_eq!(m.get_index(0).map(|(k, _)| k.as_str()), Some("first"));
Source

pub fn get_index_mut(&mut self, index: usize) -> Option<(&String, &mut Value)>

Returns a mutable reference to the key-value pair at the given index.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
if let Some((_, v)) = m.get_index_mut(0) {
    *v = Value::from(99_i64);
}
assert_eq!(m.get("a").and_then(Value::as_i64), Some(99));
Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Removes a key from the mapping, returning the value if the key was present.

This operation preserves the order of remaining elements (uses shift_remove semantics, O(n)). For order-agnostic O(1) removal, see Mapping::swap_remove.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
assert_eq!(m.remove("a").and_then(|v| v.as_i64()), Some(1));
assert!(m.remove("a").is_none());
Source

pub fn remove_entry(&mut self, key: &str) -> Option<(String, Value)>

Removes a key from the mapping, returning the key-value pair if present.

This operation preserves the order of remaining elements.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
let (k, v) = m.remove_entry("a").unwrap();
assert_eq!(k, "a");
assert_eq!(v.as_i64(), Some(1));
Source

pub fn swap_remove(&mut self, key: &str) -> Option<Value>

Removes a key by swapping it with the last element.

This is O(1) but does not preserve order. For order-preserving removal, see Mapping::remove or Mapping::shift_remove.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
m.insert("c", Value::from(3_i64));
m.swap_remove("a");
// Order is no longer guaranteed; "c" might now sit where "a" was.
assert_eq!(m.len(), 2);
Source

pub fn shift_remove(&mut self, key: &str) -> Option<Value>

Removes a key by shifting all elements after it.

This preserves order but is O(n). Equivalent to Mapping::remove.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
m.shift_remove("a");
assert_eq!(m.iter().next().map(|(k, _)| k.as_str()), Some("b"));
Source

pub fn entry(&mut self, key: impl Into<String>) -> Entry<'_, String, Value>

Gets the entry for the given key for in-place manipulation.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.entry("counter").or_insert(Value::from(0_i64));
if let Some(Value::Number(n)) = m.get_mut("counter") {
    if let Some(c) = n.as_i64() { *n = noyalib::Number::Integer(c + 1); }
}
assert_eq!(m.get("counter").and_then(Value::as_i64), Some(1));
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&String, &mut Value) -> bool,

Retains only the key-value pairs specified by the predicate.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
m.insert("c", Value::from(3_i64));
m.retain(|_k, v| v.as_i64().unwrap_or(0) >= 2);
assert_eq!(m.len(), 2);
assert!(!m.contains_key("a"));
Source

pub fn iter(&self) -> Iter<'_, String, Value>

Returns an iterator over the key-value pairs in insertion order.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
let total: i64 = m.iter().filter_map(|(_, v)| v.as_i64()).sum();
assert_eq!(total, 3);
Source

pub fn iter_mut(&mut self) -> IterMut<'_, String, Value>

Returns a mutable iterator over the key-value pairs in insertion order.

§Examples
use noyalib::{Mapping, Number, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
for (_, v) in m.iter_mut() {
    if let Value::Number(Number::Integer(n)) = v { *n *= 2; }
}
assert_eq!(m.get("a").and_then(Value::as_i64), Some(2));
Source

pub fn keys(&self) -> Keys<'_, String, Value>

Returns an iterator over the keys in insertion order.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
let keys: Vec<&str> = m.keys().map(String::as_str).collect();
assert_eq!(keys, &["a", "b"]);
Source

pub fn values(&self) -> Values<'_, String, Value>

Returns an iterator over the values in insertion order.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
let sum: i64 = m.values().filter_map(Value::as_i64).sum();
assert_eq!(sum, 3);
Source

pub fn values_mut(&mut self) -> ValuesMut<'_, String, Value>

Returns a mutable iterator over the values in insertion order.

§Examples
use noyalib::{Mapping, Number, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(10_i64));
m.insert("b", Value::from(20_i64));
for v in m.values_mut() {
    if let Value::Number(Number::Integer(n)) = v { *n /= 10; }
}
assert_eq!(m.get("a").and_then(Value::as_i64), Some(1));
Source

pub fn first(&self) -> Option<(&String, &Value)>

Returns the first key-value pair in insertion order.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
assert_eq!(m.first().map(|(k, _)| k.as_str()), Some("a"));
Source

pub fn first_mut(&mut self) -> Option<(&String, &mut Value)>

Returns a mutable reference to the first key-value pair.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
if let Some((_, v)) = m.first_mut() { *v = Value::from(99_i64); }
assert_eq!(m.get("a").and_then(Value::as_i64), Some(99));
Source

pub fn last(&self) -> Option<(&String, &Value)>

Returns the last key-value pair in insertion order.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
assert_eq!(m.last().map(|(k, _)| k.as_str()), Some("b"));
Source

pub fn last_mut(&mut self) -> Option<(&String, &mut Value)>

Returns a mutable reference to the last key-value pair.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
if let Some((_, v)) = m.last_mut() { *v = Value::from(99_i64); }
assert_eq!(m.get("b").and_then(Value::as_i64), Some(99));
Source

pub fn pop_first(&mut self) -> Option<(String, Value)>

Removes and returns the first key-value pair.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
let (k, _) = m.pop_first().unwrap();
assert_eq!(k, "a");
assert_eq!(m.len(), 1);
Source

pub fn pop_last(&mut self) -> Option<(String, Value)>

Removes and returns the last key-value pair.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
let (k, _) = m.pop_last().unwrap();
assert_eq!(k, "b");
Source

pub fn sort_keys(&mut self)

Sorts the mapping by keys (lexicographic order).

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("c", Value::from(3_i64));
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
m.sort_keys();
let keys: Vec<&str> = m.keys().map(String::as_str).collect();
assert_eq!(keys, &["a", "b", "c"]);
Source

pub fn reverse(&mut self)

Reverses the order of key-value pairs.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
m.insert("b", Value::from(2_i64));
m.reverse();
assert_eq!(m.first().map(|(k, _)| k.as_str()), Some("b"));
Source

pub fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (String, Value)>,

Extends the mapping with the contents of an iterator.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.extend([
    ("a".to_owned(), Value::from(1_i64)),
    ("b".to_owned(), Value::from(2_i64)),
]);
assert_eq!(m.len(), 2);
Source

pub fn into_inner(self) -> IndexMap<String, Value>

Consumes the mapping and returns its contents as an IndexMap.

§Examples
use noyalib::{Mapping, Value};
let mut m = Mapping::new();
m.insert("a", Value::from(1_i64));
let inner = m.into_inner();
assert_eq!(inner.len(), 1);
Source

pub fn from_inner(map: IndexMap<String, Value>) -> Self

Creates a mapping from an IndexMap.

§Examples
use indexmap::IndexMap;
use noyalib::{Mapping, Value};
let mut src = IndexMap::new();
src.insert("a".to_owned(), Value::from(1_i64));
let m = Mapping::from_inner(src);
assert_eq!(m.get("a").and_then(Value::as_i64), Some(1));

Trait Implementations§

Source§

impl Clone for Mapping

Source§

fn clone(&self) -> Mapping

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 Mapping

Source§

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

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

impl Default for Mapping

Source§

fn default() -> Mapping

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Mapping

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Mapping

Source§

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

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

impl Eq for Mapping

Source§

impl From<IndexMap<String, Value, FxBuildHasher>> for Mapping

Source§

fn from(map: IndexMap<String, Value, FxBuildHasher>) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value>> for Mapping

Source§

fn from(map: IndexMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for Value

Source§

fn from(v: Mapping) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for IndexMap<String, Value>

Source§

fn from(map: Mapping) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for IndexMap<String, Value, FxBuildHasher>

Source§

fn from(map: Mapping) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for MappingAny

Source§

fn from(map: Mapping) -> Self

Converts a Mapping (with String keys) into a MappingAny.

Source§

impl From<Vec<(String, Value)>> for Mapping

Source§

fn from(v: Vec<(String, Value)>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[(String, Value); N]> for Mapping

Source§

fn from(arr: [(String, Value); N]) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Mapping

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Mapping

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 Index<&str> for Mapping

Source§

fn index(&self, key: &str) -> &Self::Output

Index into the mapping by key.

§Panics

Panics if the key is not present in the mapping.

Source§

type Output = Value

The returned type after indexing.
Source§

impl IndexMut<&str> for Mapping

Source§

fn index_mut(&mut self, key: &str) -> &mut Self::Output

Mutably index into the mapping by key.

§Panics

Panics if the key is not present in the mapping.

Source§

impl IntoIterator for Mapping

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a Mapping

Source§

type Item = (&'a String, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Mapping

Source§

type Item = (&'a String, &'a mut Value)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Mapping

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Mapping

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Mapping

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Mapping

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Mapping

Source§

impl Value for Mapping

Available on crate feature sval only.
Source§

fn stream<'sval, S: Stream<'sval> + ?Sized>( &'sval self, stream: &mut S, ) -> Result

Stream this value through a Stream.
Source§

fn tag(&self) -> Option<Tag>

Get the tag of this value, if there is one.
Source§

fn to_bool(&self) -> Option<bool>

Try convert this value into a boolean.
Source§

fn to_f32(&self) -> Option<f32>

Try convert this value into a 32bit binary floating point number.
Source§

fn to_f64(&self) -> Option<f64>

Try convert this value into a 64bit binary floating point number.
Source§

fn to_i8(&self) -> Option<i8>

Try convert this value into a signed 8bit integer.
Source§

fn to_i16(&self) -> Option<i16>

Try convert this value into a signed 16bit integer.
Source§

fn to_i32(&self) -> Option<i32>

Try convert this value into a signed 32bit integer.
Source§

fn to_i64(&self) -> Option<i64>

Try convert this value into a signed 64bit integer.
Source§

fn to_i128(&self) -> Option<i128>

Try convert this value into a signed 128bit integer.
Source§

fn to_u8(&self) -> Option<u8>

Try convert this value into an unsigned 8bit integer.
Source§

fn to_u16(&self) -> Option<u16>

Try convert this value into an unsigned 16bit integer.
Source§

fn to_u32(&self) -> Option<u32>

Try convert this value into an unsigned 32bit integer.
Source§

fn to_u64(&self) -> Option<u64>

Try convert this value into an unsigned 64bit integer.
Source§

fn to_u128(&self) -> Option<u128>

Try convert this value into an unsigned 128bit integer.
Source§

fn to_text(&self) -> Option<&str>

Try convert this value into a text string.
Source§

fn to_binary(&self) -> Option<&[u8]>

Try convert this value into a bitstring.

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
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

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

Source§

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

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

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

Source§

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

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fmt for T
where T: Display,

Source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
Source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

Source§

impl<T> MaybeSendSync for T

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Paint for T
where T: ?Sized,

Source§

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 primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
Source§

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>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
Source§

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 bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
Source§

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 mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
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.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
Source§

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);
Source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToCompactString for T
where T: Display,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP