Skip to main content

DotArrayAccessor

Struct DotArrayAccessor 

Source
pub struct DotArrayAccessor { /* private fields */ }
Expand description

ドット記法でのデータアクセスを提供

Implementations§

Source§

impl DotArrayAccessor

Source

pub fn new() -> Self

新しいインスタンスを作成

Source

pub fn get<'a>(&mut self, data: &'a Value, key: &str) -> Option<&'a Value>

ドット記法で値を取得(missingKeys追跡付き)

例: get(&data, “user.profile.name”)

キーが見つからない場合はmissingKeysに記録してNoneを返す

Source

pub fn get_missing_keys(&self) -> &[String]

取得失敗したキーの一覧を返す

Source

pub fn clear_missing_keys(&mut self)

missingKeysをクリア

Source

pub fn set(data: &mut Value, key: &str, value: Value)

ドット記法で値を設定(静的メソッド)

例: set(&mut data, “user.profile.name”, Value::String(“Alice”.to_string()))

存在しないパスは自動的にObjectとして作成される

Source

pub fn merge(data: &mut Value, key: &str, value: Value)

値をマージ(静的メソッド)

例: merge(&mut data, “user.profile”, json!({“age”: 30}))

注意: マージ処理の各レベルで、既存値と新しい値の少なくとも一方がスカラー(非オブジェクト)である場合、上書き処理がされる。 state object では、末尾のノードは値に null を持って、末尾の値と区別されている。 このため、scalar と list の object は、自動的に上書き処理してよい。

Source

pub fn has(data: &Value, key: &str) -> bool

キーが存在するかチェック(静的メソッド)

例: has(&data, “user.profile.name”)

ドット記法でのパスを辿り、最後のキーまで存在するか確認する

Source

pub fn unset(data: &mut Value, key: &str)

値を削除(静的メソッド)

例: unset(&mut data, “user.profile.name”)

Trait Implementations§

Source§

impl Default for DotArrayAccessor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.