pub struct Value(/* private fields */);
Expand description
Represents a dynamically typed value in the template engine.
Implementations§
Source§impl Value
impl Value
Sourcepub const UNDEFINED: Value = _
pub const UNDEFINED: Value = _
The undefined value.
This constant exists because the undefined type does not exist in Rust and this is the only way to construct it.
Sourcepub fn from_serialize<T>(value: T) -> Valuewhere
T: Serialize,
pub fn from_serialize<T>(value: T) -> Valuewhere
T: Serialize,
Creates a value from something that can be serialized.
This is the method that MiniJinja will generally use whenever a serializable
object is passed to one of the APIs that internally want to create a value.
For instance this is what context!
and
render
will use.
During serialization of the value, serializing_for_value
will return
true
which makes it possible to customize serialization for MiniJinja.
For more information see serializing_for_value
.
let val = Value::from_serialize(&vec![1, 2, 3]);
This method does not fail but it might return a value that is not valid. Such
values will when operated on fail in the template engine in most situations.
This for instance can happen if the underlying implementation of Serialize
fails. There are also cases where invalid objects are silently hidden in the
engine today. This is for instance the case for when keys are used in hash maps
that the engine cannot deal with. Invalid values are considered an implementation
detail. There is currently no API to validate a value.
If the deserialization
feature is enabled then the inverse of this method
is to use the Value
type as serializer. You can pass a value into the
deserialize
method of a type that supports
serde deserialization.
Sourcepub fn from_safe_string(value: String) -> Value
pub fn from_safe_string(value: String) -> Value
Creates a value from a safe string.
A safe string is one that will bypass auto escaping. For instance if you
want to have the template engine render some HTML without the user having to
supply the |safe
filter, you can use a value of this type instead.
let val = Value::from_safe_string("<em>note</em>".into());
Sourcepub fn from_bytes(value: Vec<u8>) -> Value
pub fn from_bytes(value: Vec<u8>) -> Value
Creates a value from a byte vector.
MiniJinja can hold on to bytes and has some limited built-in support for working with them. They are non iterable and not particularly useful in the context of templates. When they are stringified, they are assumed to contain UTF-8 and will be treated as such. They become more useful when a filter can do something with them (eg: base64 encode them etc.).
This method exists so that a value can be constructed as creating a
value from a Vec<u8>
would normally just create a sequence.
Sourcepub fn from_object<T>(value: T) -> Value
pub fn from_object<T>(value: T) -> Value
Creates a value from a dynamic object.
For more information see Object
.
use std::fmt;
#[derive(Debug)]
struct Thing {
id: usize,
}
impl Object for Thing {}
let val = Value::from_object(Thing { id: 42 });
Sourcepub fn from_dyn_object<T>(value: T) -> Value
pub fn from_dyn_object<T>(value: T) -> Value
Like from_object
but for type erased dynamic objects.
This especially useful if you have an object that has an Arc<T>
to another
child object that you want to return as a Arc<T>
turns into a DynObject
automatically.
#[derive(Debug)]
pub struct HttpConfig {
port: usize,
}
#[derive(Debug)]
struct Config {
http: Arc<HttpConfig>,
}
impl Object for HttpConfig {
fn enumerate(self: &Arc<Self>) -> Enumerator {
Enumerator::Str(&["port"])
}
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"port" => Some(Value::from(self.port)),
_ => None,
}
}
}
impl Object for Config {
fn enumerate(self: &Arc<Self>) -> Enumerator {
Enumerator::Str(&["http"])
}
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"http" => Some(Value::from_dyn_object(self.http.clone())),
_ => None
}
}
}
Sourcepub fn make_iterable<I, T, F>(maker: F) -> Value
pub fn make_iterable<I, T, F>(maker: F) -> Value
Creates a value that is an iterable.
The function is invoked to create a new iterator every time the value is iterated over.
let val = Value::make_iterable(|| 0..10);
Iterators that implement ExactSizeIterator
or have a matching lower and upper
bound on the Iterator::size_hint
report a known loop.length
. Iterators that
do not fulfill these requirements will not. The same is true for revindex
and
similar properties.
Sourcepub fn make_object_iterable<T, F>(object: T, maker: F) -> Value
pub fn make_object_iterable<T, F>(object: T, maker: F) -> Value
Creates an iterable that iterates over the given value.
This is similar to make_iterable
but it takes an extra
reference to a value it can borrow out from. It’s a bit less generic in that it
needs to return a boxed iterator of values directly.
let val = Value::make_object_iterable(vec![1, 2, 3], |vec| {
Box::new(vec.iter().copied().map(Value::from))
});
assert_eq!(val.to_string(), "[1, 2, 3]");
Sourcepub fn make_one_shot_iterator<I, T>(iter: I) -> Value
pub fn make_one_shot_iterator<I, T>(iter: I) -> Value
Creates a value from a one-shot iterator.
This takes an iterator (yielding values that can be turned into a Value
)
and wraps it in a way that it turns into an iterable value. From the view of
the template this can be iterated over exactly once for the most part once
exhausted.
Such iterators are strongly recommended against in the general sense due to their surprising behavior, but they can be useful for more advanced use cases where data should be streamed into the template as it becomes available.
Such iterators never have any size hints.
let val = Value::make_one_shot_iterator(0..10);
Attempting to iterate over it a second time will not yield any more items.
Sourcepub fn from_function<F, Rv, Args>(f: F) -> Valuewhere
F: Function<Rv, Args> + for<'a> Function<Rv, <Args as FunctionArgs<'a>>::Output>,
Rv: FunctionResult,
Args: for<'a> FunctionArgs<'a>,
pub fn from_function<F, Rv, Args>(f: F) -> Valuewhere
F: Function<Rv, Args> + for<'a> Function<Rv, <Args as FunctionArgs<'a>>::Output>,
Rv: FunctionResult,
Args: for<'a> FunctionArgs<'a>,
Creates a callable value from a function.
let pow = Value::from_function(|a: u32| a * a);
Sourcepub fn kind(&self) -> ValueKind
pub fn kind(&self) -> ValueKind
Returns the kind of the value.
This can be used to determine what’s in the value before trying to perform operations on it.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the number is a real integer.
This can be used to distinguish 42
from 42.0
. For the most part
the engine keeps these the same.
Sourcepub fn is_true(&self) -> bool
pub fn is_true(&self) -> bool
Is this value considered true?
The engine inherits the same behavior as Jinja2 when it comes to
considering objects true. Empty objects are generally not considered
true. For custom objects this is customized by Object::is_true
.
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true
if this value is undefined.
Sourcepub fn to_str(&self) -> Option<Arc<str>>
pub fn to_str(&self) -> Option<Arc<str>>
If the value is a string, return it.
This will also perform a lossy string conversion of bytes from utf-8.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If the value is a string, return it.
This will also return well formed utf-8 bytes as string.
Sourcepub fn as_object(&self) -> Option<&DynObject>
pub fn as_object(&self) -> Option<&DynObject>
If the value is an object a reference to it is returned.
The returned value is a reference to a type erased DynObject
.
For a specific type use downcast_object
instead.
Sourcepub fn len(&self) -> Option<usize>
pub fn len(&self) -> Option<usize>
Returns the length of the contained value.
Values without a length will return None
.
let seq = Value::from(vec![1, 2, 3, 4]);
assert_eq!(seq.len(), Some(4));
Sourcepub fn get_attr(&self, key: &str) -> Result<Value, Error>
pub fn get_attr(&self, key: &str) -> Result<Value, Error>
Looks up an attribute by attribute name.
This this returns UNDEFINED
when an invalid key is
resolved. An error is returned if the value does not contain an object
that has attributes.
let ctx = minijinja::context! {
foo => "Foo"
};
let value = ctx.get_attr("foo")?;
assert_eq!(value.to_string(), "Foo");
Sourcepub fn get_item_by_index(&self, idx: usize) -> Result<Value, Error>
pub fn get_item_by_index(&self, idx: usize) -> Result<Value, Error>
Looks up an index of the value.
This is a shortcut for get_item
.
let seq = Value::from(vec![0u32, 1, 2]);
let value = seq.get_item_by_index(1).unwrap();
assert_eq!(value.try_into().ok(), Some(1));
Sourcepub fn get_item(&self, key: &Value) -> Result<Value, Error>
pub fn get_item(&self, key: &Value) -> Result<Value, Error>
Looks up an item (or attribute) by key.
This is similar to get_attr
but instead of using
a string key this can be any key. For instance this can be used to
index into sequences. Like get_attr
this returns
UNDEFINED
when an invalid key is looked up.
let ctx = minijinja::context! {
foo => "Foo",
};
let value = ctx.get_item(&Value::from("foo")).unwrap();
assert_eq!(value.to_string(), "Foo");
Sourcepub fn try_iter(&self) -> Result<ValueIter, Error>
pub fn try_iter(&self) -> Result<ValueIter, Error>
Iterates over the value.
Depending on the kind
of the value the iterator
has a different behavior.
ValueKind::Map
: the iterator yields the keys of the map.ValueKind::Seq
/ValueKind::Iterable
: the iterator yields the items in the sequence.ValueKind::String
: the iterator yields characters in a string.ValueKind::None
/ValueKind::Undefined
: the iterator is empty.
let value = Value::from({
let mut m = std::collections::BTreeMap::new();
m.insert("foo", 42);
m.insert("bar", 23);
m
});
for key in value.try_iter()? {
let value = value.get_item(&key)?;
println!("{} = {}", key, value);
}
Sourcepub fn reverse(&self) -> Result<Value, Error>
pub fn reverse(&self) -> Result<Value, Error>
Returns a reversed view of this value.
This is implemented for the following types with the following behaviors:
- undefined or none: value returned unchanged.
- string and bytes: returns a reversed version of that value
- iterables: returns a reversed version of the iterable. If the iterable is not reversible itself, it consumes it and then reverses it.
Sourcepub fn downcast_object_ref<T>(&self) -> Option<&T>where
T: 'static,
pub fn downcast_object_ref<T>(&self) -> Option<&T>where
T: 'static,
Returns some reference to the boxed object if it is of type T
, or None if it isn’t.
This is basically the “reverse” of from_object
and from_dyn_object
. It’s also a shortcut for
downcast_ref
on the return value of
as_object
.
§Example
use std::fmt;
#[derive(Debug)]
struct Thing {
id: usize,
}
impl Object for Thing {}
let x_value = Value::from_object(Thing { id: 42 });
let thing = x_value.downcast_object_ref::<Thing>().unwrap();
assert_eq!(thing.id, 42);
Sourcepub fn downcast_object<T>(&self) -> Option<Arc<T>>where
T: 'static,
pub fn downcast_object<T>(&self) -> Option<Arc<T>>where
T: 'static,
Like downcast_object_ref
but returns
the actual object.
Sourcepub fn call(
&self,
state: &State<'_, '_>,
args: &[Value],
) -> Result<Value, Error>
pub fn call( &self, state: &State<'_, '_>, args: &[Value], ) -> Result<Value, Error>
Calls the value directly.
If the value holds a function or macro, this invokes it. Note that in
MiniJinja there is a separate namespace for methods on objects and callable
items. To call methods (which should be a rather rare occurrence) you
have to use call_method
.
The args
slice is for the arguments of the function call. To pass
keyword arguments use the Kwargs
type.
Usually the state is already available when it’s useful to call this method,
but when it’s not available you can get a fresh template state straight
from the Template
via new_state
.
let func = Value::from_function(|v: i64, kwargs: Kwargs| {
v * kwargs.get::<i64>("mult").unwrap_or(1)
});
let rv = func.call(
state,
&[
Value::from(42),
Value::from(Kwargs::from_iter([("mult", Value::from(2))])),
],
).unwrap();
assert_eq!(rv, Value::from(84));
With the args!
macro creating an argument slice is
simplified:
let func = Value::from_function(|v: i64, kwargs: Kwargs| {
v * kwargs.get::<i64>("mult").unwrap_or(1)
});
let rv = func.call(state, args!(42, mult => 2)).unwrap();
assert_eq!(rv, Value::from(84));
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<'de, 'v> Deserializer<'de> for &'v Value
impl<'de, 'v> Deserializer<'de> for &'v Value
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_option<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_option<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moreSource§fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a newtype struct with a
particular name.Source§fn deserialize_bool<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.Source§fn deserialize_u8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u8
value.Source§fn deserialize_u16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u16
value.Source§fn deserialize_u32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u32
value.Source§fn deserialize_u64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u64
value.Source§fn deserialize_i8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i8
value.Source§fn deserialize_i16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i16
value.Source§fn deserialize_i32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i32
value.Source§fn deserialize_i64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i64
value.Source§fn deserialize_f32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f32
value.Source§fn deserialize_f64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f64
value.Source§fn deserialize_char<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.Source§fn deserialize_str<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_string<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_unit<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit value.Source§fn deserialize_seq<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values.Source§fn deserialize_bytes<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_byte_buf<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_map<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a map of key-value pairs.Source§fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a struct with a particular
name and fields.Source§fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_ignored_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn deserialize_identifier<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <&'v Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read moreSource§impl<'de> Deserializer<'de> for Value
impl<'de> Deserializer<'de> for Value
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_option<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_option<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moreSource§fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a newtype struct with a
particular name.Source§fn deserialize_bool<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.Source§fn deserialize_u8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u8
value.Source§fn deserialize_u16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u16
value.Source§fn deserialize_u32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u32
value.Source§fn deserialize_u64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u64
value.Source§fn deserialize_i8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i8
value.Source§fn deserialize_i16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i16
value.Source§fn deserialize_i32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i32
value.Source§fn deserialize_i64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i64
value.Source§fn deserialize_f32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f32
value.Source§fn deserialize_f64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f64
value.Source§fn deserialize_char<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.Source§fn deserialize_str<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_string<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_unit<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit value.Source§fn deserialize_seq<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values.Source§fn deserialize_bytes<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_byte_buf<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_map<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a map of key-value pairs.Source§fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a struct with a particular
name and fields.Source§fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_ignored_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn deserialize_identifier<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, <Value as Deserializer<'de>>::Error>where
V: Visitor<'de>,
Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read moreSource§impl<T> From<LinkedList<T>> for Value
impl<T> From<LinkedList<T>> for Value
Source§fn from(val: LinkedList<T>) -> Value
fn from(val: LinkedList<T>) -> Value
Source§impl<K, V> FromIterator<(K, V)> for Value
impl<K, V> FromIterator<(K, V)> for Value
Source§impl<V> FromIterator<V> for Value
impl<V> FromIterator<V> for Value
Source§impl<'de> IntoDeserializer<'de, Error> for &'de Value
impl<'de> IntoDeserializer<'de, Error> for &'de Value
Source§type Deserializer = &'de Value
type Deserializer = &'de Value
Source§fn into_deserializer(self) -> &'de Value
fn into_deserializer(self) -> &'de Value
Source§impl<'de> IntoDeserializer<'de, Error> for Value
impl<'de> IntoDeserializer<'de, Error> for Value
Source§type Deserializer = Value
type Deserializer = Value
Source§fn into_deserializer(self) -> Value
fn into_deserializer(self) -> Value
Source§impl Ord for Value
impl Ord for Value
Source§impl PartialOrd for Value
impl PartialOrd for Value
Source§impl Serialize for Value
impl Serialize for Value
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Eq for Value
Auto Trait Implementations§
impl Freeze for Value
impl !RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl !UnwindSafe for Value
Blanket Implementations§
Source§impl<T> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<I> FunctionResult for I
impl<I> FunctionResult for I
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
Source§fn bright_yellow(&self) -> Painted<&T>
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>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
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>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
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>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
Source§fn on_bright_yellow(&self) -> Painted<&T>
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>
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>
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>
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>
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>
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 underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);