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 get_index_of(&self, key: &str) -> Option<usize>

Returns the index of the given key, if present.

Indexing follows insertion order (this is an IndexMap); a key keeps its original index when its value is overwritten by a later Mapping::insert.

§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_of("second"), Some(1));
assert_eq!(m.get_index_of("absent"), None);
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<'a> Arbitrary<'a> for Mapping

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
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

Available on crate feature std only.
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>

Available on crate feature std only.
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

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

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

Inequality operator !=. Read more
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

Source§

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

Stream this value through a [Stream].
§

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

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

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

Try convert this value into a boolean.
§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Try convert this value into a text string.
§

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
§

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

§

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 ()

§

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<T> ErasedDestructor for T
where T: 'static,

§

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

§

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

Give this value the specified foreground colour.
§

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
§

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

§

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

§

impl<T> MaybeSendSync for T

§

impl<D> OwoColorize for D

§

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

Set the foreground color generically Read more
§

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

Set the background color generically. Read more
§

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

Change the foreground color to black
§

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

Change the background color to black
§

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

Change the foreground color to red
§

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

Change the background color to red
§

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

Change the foreground color to green
§

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

Change the background color to green
§

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

Change the foreground color to yellow
§

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

Change the background color to yellow
§

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

Change the foreground color to blue
§

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

Change the background color to blue
§

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

Change the foreground color to magenta
§

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

Change the background color to magenta
§

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

Change the foreground color to purple
§

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

Change the background color to purple
§

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

Change the foreground color to cyan
§

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

Change the background color to cyan
§

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

Change the foreground color to white
§

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

Change the background color to white
§

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

Change the foreground color to the terminal default
§

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

Change the background color to the terminal default
§

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

Change the foreground color to bright black
§

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

Change the background color to bright black
§

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

Change the foreground color to bright red
§

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

Change the background color to bright red
§

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

Change the foreground color to bright green
§

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

Change the background color to bright green
§

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

Change the foreground color to bright yellow
§

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

Change the background color to bright yellow
§

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

Change the foreground color to bright blue
§

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

Change the background color to bright blue
§

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

Change the foreground color to bright magenta
§

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

Change the background color to bright magenta
§

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

Change the foreground color to bright purple
§

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

Change the background color to bright purple
§

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

Change the foreground color to bright cyan
§

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

Change the background color to bright cyan
§

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

Change the foreground color to bright white
§

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

Change the background color to bright white
§

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

Make the text bold
§

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

Make the text dim
§

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

Make the text italicized
§

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

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

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

Swap the foreground and background colors
§

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

Hide the text
§

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

Cross out the text
§

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
§

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
§

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

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

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

Sets the foreground color to an RGB value.
§

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

Sets the background color to an RGB value.
§

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

Apply a runtime-determined style
§

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

§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Create a new [Painted] with a default [Style]. Read more
§

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. Read more
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.
§

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

§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP