Struct StyleBuilder

Source
pub struct StyleBuilder<'a> { /* private fields */ }
Expand description

Builder to customise path styling

Implementations§

Source§

impl<'a> StyleBuilder<'a>

Source

pub fn new() -> Self

Source

pub fn default_object_key_prefix(self) -> Self

Clears the currently specified object key prefix value

Source

pub fn object_key_prefix(self, value: &'a str) -> Self

Sets the object key prefix value

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .object_key_prefix(">>>")
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: ">>>apple\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_object_key_suffix(self) -> Self

Clears the currently specified object key suffix value

Source

pub fn object_key_suffix(self, value: &'a str) -> Self

Sets the object key suffix value

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .object_key_suffix("$$$")
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple$$$[0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_object_keys_in_path(self) -> Self

Clears whether to show or hide object key values in the Element path

Source

pub fn show_object_keys_in_path(self) -> Self

Sets the object key values to be visible in the Element path

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .show_object_keys_in_path()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn hide_object_keys_in_path(self) -> Self

Sets the object key values to be hidden in the Element path

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .hide_object_keys_in_path()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_object_parents(self) -> Self

Clears whether to skip or include values that are objects in the set of yielded values

Source

pub fn skip_object_parents(self) -> Self

Sets values that are objects to be yielded by the Iterator

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .skip_object_parents()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn include_object_parents(self) -> Self

Prevents values that are objects from being yielded by the Iterator

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .include_object_parents()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "".into(), indices: vec![], value: &json!({"apple": [1, true, "three"]}), });
Source

pub fn default_array_key_prefix(self) -> Self

Clears the currently specified array_key_prefix value

Source

pub fn array_key_prefix(self, value: &'a str) -> Self

Sets the array_key_prefix value

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .array_key_prefix(":::")
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"]:::0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_array_key_suffix(self) -> Self

Clears the currently specified array key suffix value

Source

pub fn array_key_suffix(self, value: &'a str) -> Self

Sets the array key suffix value

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .array_key_suffix("!!!")
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][0!!!".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_array_keys_in_path(self) -> Self

Clears whether to show or hide array key values in the Element path

Source

pub fn show_array_keys_in_path(self) -> Self

Sets the array key values to be visible in the Element path

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .show_array_keys_in_path()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn hide_array_keys_in_path(self) -> Self

Sets the array key values to be hidden in the Element path

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .hide_array_keys_in_path()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn default_array_parents(self) -> Self

Clears whether to skip or include values that are arrays in the set of yielded values

Source

pub fn skip_array_parents(self) -> Self

Sets values that are arrays to be yielded by the Iterator

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .skip_array_parents()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"][0]".into(), indices: vec![0], value: &json!(1), });
Source

pub fn include_array_parents(self) -> Self

Prevents values that are arrays from being yielded by the Iterator

use serde_json::json;
use json_keypath_iter::{Style, StyleBuilder, Iterator, Element};

let style: Style = StyleBuilder::new()
    .include_array_parents()
    .build();
let value = json!({"apple": [1, true, "three"]});
let iter = Iterator::new(&value).use_style(style);
let items: Vec<_> = iter.collect();

assert_eq!(items[0], Element { path: "[\"apple\"]".into(), indices: vec![], value: &json!([1, true, "three"]), });
Source

pub fn build(&self) -> Style<'a>

Builds a value Style with defaults for any value not specified or previously cleared out

Trait Implementations§

Source§

impl<'a> From<PresetStyle> for StyleBuilder<'a>

Source§

fn from(style: PresetStyle) -> StyleBuilder<'a>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for StyleBuilder<'a>

§

impl<'a> RefUnwindSafe for StyleBuilder<'a>

§

impl<'a> Send for StyleBuilder<'a>

§

impl<'a> Sync for StyleBuilder<'a>

§

impl<'a> Unpin for StyleBuilder<'a>

§

impl<'a> UnwindSafe for StyleBuilder<'a>

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