pub enum ShapeCase {
}Expand description
The ShapeCase enum attempts to capture all the common shapes of JSON
values, not just the JSON types themselves, but also patterns of usage (such
as using JSON arrays as either static tuples or dynamic lists).
A ShapeCase enum variant like ShapeCase::One may temporarily
represent a structure that has not been fully simplified, but simplication
is required to turn the ShapeCase into a Shape, using the
ShapeCase::simplify(&self) -> Shape method.
Variants§
Bool(Option<bool>)
The Bool, String, and Int variants can either represent a general
shape using None for the Option, or a specific shape using Some.
For example, ShapeCase::Bool(None) is a shape satisfied by either true
or false, like the Rust bool type, while ShapeCase::Bool(Some(true))
is a shape satisfied only by true (and likewise for false).
String(Option<String>)
Similar to ShapeCase::Bool, ShapeCase::String represents a shape
matching either any string (in the None case) or some specific string
(in the Some case).
Int(Option<i64>)
Similar to ShapeCase::Bool and ShapeCase::String,
ShapeCase::Int can represent either any integer or some specific
integer.
Float
ShapeCase::Float is a shape that captures the set of all floating
point numbers. We do not allow singleton floating point value shapes,
since floating point equality is unreliable.
Null
ShapeCase::Null is a singleton shape whose only possible value is
null. Note that ShapeCase::Null is different from
ShapeCase::None, which represents the absence of a value.
Array
ShapeCase::Array represents a prefix of statically known shapes
(like a tuple type), followed by an optional tail shape for all other
(dynamic) elements. When only the prefix elements are defined, the
tail shape is ShapeCase::None. ShapeCase::Array(vec![], ShapeCase::None) is the shape of an empty array.
Object
ShapeCase::Object is a map of statically known field names to field
shapes, together with an optional type for all other string keys. When
dynamic string indexing is disabled, the rest shape will be
ShapeCase::None. Note that accessing the dynamic map always returns
ShapeCase::One([rest_shape, ShapeCase::None]), to reflect the
uncertainty of the shape of dynamic keys not present in the static
fields.
One(One)
A union of shapes, satisfied by values that satisfy any of the shapes in the set.
Create using Shape::one.
All(All)
An intersection of shapes, satisfied by values that satisfy all of the
shapes in the set. When applied to multiple ShapeCase::Object
shapes, ShapeCase::All represents merging the fields of the objects,
as reflected by the simplification logic.
Crete using Shape::all.
Name(Located<String>, Vec<Located<NamedShapePathKey>>)
ShapeCase::Name refers to a shape declared with the given name,
possibly in the future. When shape processing needs to refer to the
shape of some subproperty of a named shape, it uses the
Vec<NamedShapePathKey> subpath to represent the nested shape. When the
named shape is eventually declared, the subpath can be used to resolve
the actual shape of the nested property path.
As of now, the name String is expected to be either an identifier or a
variable name like $root or $this or $args, allowing
ShapeCase::Name to represent types of subproperties of variables as
well as named types from some schema.
Unknown
ShapeCase::Unknown is a shape that represents any possible JSON
value (including ShapeCase::None).
None
Represents the absence of a value, or the shape of a property not
present in an object. Used by the rest parameters of both
ShapeCase::Array and ShapeCase::Object to indicate no additional
dynamic elements are allowed, and with ShapeCase::One to represent
optionality of values, e.g. One<Bool, None>.
Error(Error)
Represents a local failure of shape processing.
Implementations§
Source§impl ShapeCase
impl ShapeCase
Source§impl ShapeCase
impl ShapeCase
Sourcepub fn from_json(json: &JSON) -> Self
pub fn from_json(json: &JSON) -> Self
Derive a ShapeCase from a serde_json::Value.
§Panics
If the serde_json::Value can’t be converted into a [serde_json_bytes::Value]
pub fn from_json_bytes(json: &JSONBytes) -> Self
Trait Implementations§
Source§impl Hash for ShapeCase
Because ShapeCase uses [IndexMap] and [IndexSet] for its Object, One, and All
variants, the default derived Hash trait implementation does not work.
Instead, we hash those cases manually, using a commutative operation to
combine the order-insensitive hashes of the elements.
impl Hash for ShapeCase
Because ShapeCase uses [IndexMap] and [IndexSet] for its Object, One, and All
variants, the default derived Hash trait implementation does not work.
Instead, we hash those cases manually, using a commutative operation to
combine the order-insensitive hashes of the elements.
impl Eq for ShapeCase
impl StructuralPartialEq for ShapeCase
Auto Trait Implementations§
impl Freeze for ShapeCase
impl RefUnwindSafe for ShapeCase
impl Send for ShapeCase
impl Sync for ShapeCase
impl Unpin for ShapeCase
impl UnwindSafe for ShapeCase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);