pub struct Collection<T: Ord> { /* private fields */ }Expand description
The kinds of a collection (e.g. array or object).
A collection contains one or more kinds for known positions within the collection (e.g. indices or fields), and contains a global “unknown” state that applies to all unknown paths.
Implementations§
Source§impl Collection<Index>
impl Collection<Index>
Sourcepub fn largest_known_index(&self) -> Option<usize>
pub fn largest_known_index(&self) -> Option<usize>
Returns the largest known index, or None if no known indices exist.
Sourcepub fn get_positive_index(&self, index: isize) -> Option<usize>
pub fn get_positive_index(&self, index: isize) -> Option<usize>
Converts a negative index to a positive index (only if the exact positive index is known).
Sourcepub fn min_length(&self) -> usize
pub fn min_length(&self) -> usize
The minimum possible length an array could be given the type information.
Sourcepub fn exact_length(&self) -> Option<usize>
pub fn exact_length(&self) -> Option<usize>
The exact length of the array, if it can be proven. Otherwise, None.
Sourcepub fn remove_shift(&mut self, index: usize)
pub fn remove_shift(&mut self, index: usize)
Removes the known value at the given index and shifts the elements to the left.
Source§impl<T: Ord + Clone> Collection<T>
impl<T: Ord + Clone> Collection<T>
Sourcepub fn from_parts(known: BTreeMap<T, Kind>, unknown: impl Into<Kind>) -> Self
pub fn from_parts(known: BTreeMap<T, Kind>, unknown: impl Into<Kind>) -> Self
Create a new collection from its parts.
Sourcepub fn from_unknown(unknown: impl Into<Kind>) -> Self
pub fn from_unknown(unknown: impl Into<Kind>) -> Self
Create a new collection with a defined “unknown fields” value, and no known fields.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create a collection kind of which there are no known and no unknown kinds.
Sourcepub fn any() -> Self
pub fn any() -> Self
Create a collection kind of which the encapsulated values can be any kind.
Sourcepub fn json() -> Self
pub fn json() -> Self
Create a collection kind of which the encapsulated values can be any JSON-compatible kind.
Sourcepub fn is_any(&self) -> bool
pub fn is_any(&self) -> bool
Check if the collection fields can be of any kind.
This returns false if at least one field kind is known.
Sourcepub fn known(&self) -> &BTreeMap<T, Kind>
pub fn known(&self) -> &BTreeMap<T, Kind>
Get a reference to the “known” elements in the collection.
Sourcepub fn known_mut(&mut self) -> &mut BTreeMap<T, Kind>
pub fn known_mut(&mut self) -> &mut BTreeMap<T, Kind>
Get a mutable reference to the “known” elements in the collection.
Sourcepub fn unknown_kind(&self) -> Kind
pub fn unknown_kind(&self) -> Kind
Gets the type of “unknown” elements in the collection. The returned type will always have “undefined” included.
Sourcepub fn is_unknown_exact(&self) -> bool
pub fn is_unknown_exact(&self) -> bool
Returns true if the unknown variant is “Exact” (vs “Infinite”). This can be used to determine when to stop recursing into an unknown kind. Once the unknown is infinite, this will return false and all unknowns after that will return the same kind.
Sourcepub fn set_unknown(&mut self, unknown: impl Into<Kind>)
pub fn set_unknown(&mut self, unknown: impl Into<Kind>)
Set all “unknown” collection elements to the given kind.
Sourcepub fn with_unknown(self, unknown: impl Into<Kind>) -> Self
pub fn with_unknown(self, unknown: impl Into<Kind>) -> Self
Returns a new collection with the unknown set.
Sourcepub fn with_known(self, key: impl Into<T>, kind: Kind) -> Self
pub fn with_known(self, key: impl Into<T>, kind: Kind) -> Self
Returns a new collection that includes the known key.
Sourcepub fn anonymize(&mut self)
pub fn anonymize(&mut self)
Given a collection of known and unknown types, merge the known types with the unknown type, and remove a reference to the known types.
That is, given an object with field “foo” as integer, “bar” as bytes and unknown fields as timestamp, after calling this function, the object has no known fields, and all unknown fields are marked as either an integer, bytes or timestamp.
Recursively known fields are left untouched. For example, an object with a field “foo” that has an object with a field “bar” results in a collection of which any field can have an object that has a field “bar”.
Sourcepub fn merge(&mut self, other: Self, overwrite: bool)
pub fn merge(&mut self, other: Self, overwrite: bool)
Merge the other collection into self.
The following merge strategies are applied.
For known fields:
-
If a field exists in both collections, their
Kinds are merged, or theotherfields are used (depending on the configuredStrategy). -
If a field exists in one but not the other, the field is merged with the “unknown” of the other if it exists, or just the field is used otherwise.
For unknown fields or indices:
- Both
Unknowns are merged, similar to merging twoKinds.
Sourcepub fn reduced_kind(&self) -> Kind
pub fn reduced_kind(&self) -> Kind
Return the reduced Kind of the items within the collection.
This only returns the type of defined values in the collection. Accessing
a non-existing value can return undefined which is not added to the type here.
Source§impl<T: Ord + Clone + CollectionKey> Collection<T>
impl<T: Ord + Clone + CollectionKey> Collection<T>
Sourcepub fn is_superset(&self, other: &Self) -> Result<(), OwnedValuePath>
pub fn is_superset(&self, other: &Self) -> Result<(), OwnedValuePath>
Check if self is a superset of other.
Meaning, for all known fields in other, if the field also exists in self, then its type
needs to be a subset of self, otherwise its type needs to be a subset of self’s
unknown.
If self has known fields not defined in other, then other’s unknown must be
a superset of those fields defined in self.
Additionally, other’s unknown type needs to be a subset of self’s.
§Errors
If the type is not a superset, a path to one field that doesn’t match is returned. This is mostly useful for debugging.
Trait Implementations§
Source§impl<T: Clone + Ord> Clone for Collection<T>
impl<T: Clone + Ord> Clone for Collection<T>
Source§fn clone(&self) -> Collection<T>
fn clone(&self) -> Collection<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Display for Collection<Field>
impl Display for Collection<Field>
Source§impl Display for Collection<Index>
impl Display for Collection<Index>
Source§impl From<Collection<Field>> for Kind
impl From<Collection<Field>> for Kind
Source§fn from(collection: Collection<Field>) -> Self
fn from(collection: Collection<Field>) -> Self
Source§impl From<Collection<Index>> for Kind
impl From<Collection<Index>> for Kind
Source§fn from(collection: Collection<Index>) -> Self
fn from(collection: Collection<Index>) -> Self
Source§impl<T: PartialOrd + Ord> PartialOrd for Collection<T>
impl<T: PartialOrd + Ord> PartialOrd for Collection<T>
impl<T: Eq + Ord> Eq for Collection<T>
impl<T: Ord> StructuralPartialEq for Collection<T>
Auto Trait Implementations§
impl<T> Freeze for Collection<T>
impl<T> RefUnwindSafe for Collection<T>where
T: RefUnwindSafe,
impl<T> Send for Collection<T>where
T: Send,
impl<T> Sync for Collection<T>where
T: Sync,
impl<T> Unpin for Collection<T>
impl<T> UnwindSafe for Collection<T>where
T: RefUnwindSafe,
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
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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
type Error = <Target as OctetsFrom<Source>>::Error
§fn try_octets_into(
self,
) -> Result<Target, <Source as OctetsInto<Target>>::Error>
fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>
§fn octets_into(self) -> Targetwhere
Self::Error: Into<Infallible>,
fn octets_into(self) -> Targetwhere
Self::Error: Into<Infallible>,
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
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,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
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>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self,
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
§fn if_supports_color<'a, Out, ApplyFn>(
&'a self,
stream: impl Into<Stream>,
apply: ApplyFn,
) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn>where
ApplyFn: Fn(&'a Self) -> Out,
fn if_supports_color<'a, Out, ApplyFn>(
&'a self,
stream: impl Into<Stream>,
apply: ApplyFn,
) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn>where
ApplyFn: Fn(&'a Self) -> Out,
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.