pub struct DocPath { /* private fields */ }Implementations§
Source§impl DocPath
impl DocPath
Sourcepub fn new(expr: impl Into<String>) -> Result<Self>
pub fn new(expr: impl Into<String>) -> Result<Self>
Construct a new document path from the provided string path
Sourcepub fn new_unwrap(expr: &'static str) -> Self
pub fn new_unwrap(expr: &'static str) -> Self
Infallible construction for when the expression is statically known, intended for unit tests.
Invalid expressions will still cause panics.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Construct a new DocPath with an empty expression.
Warning: do not call any of the push_* methods on this DocPath,
as that would create an expression with invalid syntax
(because it would be missing the Root token).
Sourcepub fn from_tokens<I>(tokens: I) -> Selfwhere
I: IntoIterator<Item = PathToken>,
pub fn from_tokens<I>(tokens: I) -> Selfwhere
I: IntoIterator<Item = PathToken>,
Construct a new DocPath from a list of tokens
Sourcepub fn last(&self) -> Option<PathToken>
pub fn last(&self) -> Option<PathToken>
Returns the last item in the path. Will panic if the path is empty.
Sourcepub fn first_field(&self) -> Option<&str>
pub fn first_field(&self) -> Option<&str>
Extract the string contents of the first Field token. For use with Header and Query DocPaths.
Sourcepub fn last_field(&self) -> Option<&str>
pub fn last_field(&self) -> Option<&str>
Extract the string contents of the last Field token.
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
If this path is the root path (it has only one element, the root token $).
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
The path is a wildcard path if it ends in a star (*)
Sourcepub fn path_weight(&self, path: &[&str]) -> (usize, usize)
pub fn path_weight(&self, path: &[&str]) -> (usize, usize)
Calculates the path weight for this path expression and a given path. Returns a tuple of the calculated weight and the number of path tokens matched.
Sourcepub fn matches_path(&self, path: &[&str]) -> bool
pub fn matches_path(&self, path: &[&str]) -> bool
If this path matches the given path. It will match if the calculated path weight is greater than zero (which means at least one token matched).
Sourcepub fn matches_path_exactly(&self, path: &[&str]) -> bool
pub fn matches_path_exactly(&self, path: &[&str]) -> bool
If the path matches the given path (the calculated path weight is greater than zero) and both paths have the same length.
Sourcepub fn join(&self, part: impl Into<String>) -> Self
pub fn join(&self, part: impl Into<String>) -> Self
Creates a new path by cloning this one and pushing the string onto the end
Sourcepub fn join_index(&self, index: usize) -> Self
pub fn join_index(&self, index: usize) -> Self
Creates a new path by cloning this one and joining the index onto the end. Paths that end
with * will have the * replaced with the index.
Sourcepub fn join_field<S: Into<String>>(&self, name: S) -> Self
pub fn join_field<S: Into<String>>(&self, name: S) -> Self
Creates a new path by cloning this one and joining the field onto the end. Paths that end
with * will have the * replaced with the field.
Sourcepub fn push_field(&mut self, field: impl Into<String>) -> &mut Self
pub fn push_field(&mut self, field: impl Into<String>) -> &mut Self
Mutates this path by pushing a field value onto the end.
Sourcepub fn push_index(&mut self, index: usize) -> &mut Self
pub fn push_index(&mut self, index: usize) -> &mut Self
Mutates this path by pushing an index value onto the end.
Sourcepub fn push_star(&mut self) -> &mut Self
pub fn push_star(&mut self) -> &mut Self
Mutates this path by pushing a star value onto the end.
Sourcepub fn push_star_index(&mut self) -> &mut Self
pub fn push_star_index(&mut self) -> &mut Self
Mutates this path by pushing a star index value onto the end.
Sourcepub fn push(&mut self, path_token: PathToken) -> &mut Self
pub fn push(&mut self, path_token: PathToken) -> &mut Self
Mutates this path by pushing a path token onto the end.
Sourcepub fn push_path(&mut self, path: &DocPath) -> &mut Self
pub fn push_path(&mut self, path: &DocPath) -> &mut Self
Mutates this path by pushing another path onto the end. Will drop the root marker from the other path
Sourcepub fn to_lower_case(&self) -> DocPath
pub fn to_lower_case(&self) -> DocPath
Returns a copy of this path will all parts lower case
Sourcepub fn as_json_pointer(&self) -> Result<String>
pub fn as_json_pointer(&self) -> Result<String>
Converts this path into a JSON pointer RFC6901.
Sourcepub fn ends_with(&self, suffix: &str) -> bool
pub fn ends_with(&self, suffix: &str) -> bool
If this path (as a string) ends with the given string
Sourcepub fn starts_with(&self, prefix: &str) -> bool
pub fn starts_with(&self, prefix: &str) -> bool
If this path (as a string) starts with the given string
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DocPath
impl<'de> Deserialize<'de> for DocPath
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for DocPath
Source§impl Ord for DocPath
impl Ord for DocPath
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for DocPath
impl PartialOrd for DocPath
Auto Trait Implementations§
impl Freeze for DocPath
impl RefUnwindSafe for DocPath
impl Send for DocPath
impl Sync for DocPath
impl Unpin for DocPath
impl UnsafeUnpin for DocPath
impl UnwindSafe for DocPath
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
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>
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>
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>
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>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
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>
renamed to 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);