Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

ValueEditor

Struct ValueEditor 

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

An editor for a Value obtained from a DocStore.

This provides a mutable lens into a value, allowing modifications to be staged and then saved back to the DocStore.

Implementations§

Source§

impl<'a> ValueEditor<'a>

Source

pub fn new<K>(kv_store: &'a DocStore, keys: K) -> Self
where K: Into<Vec<String>>,

Source

pub async fn get(&self) -> Result<Value>

Uses the stored keys to traverse the nested data structure and retrieve the value.

This method starts from the fully merged view of the DocStore’s subtree (local Transaction changes layered on top of backend state) and navigates using the path specified by self.keys. If self.keys is empty, it retrieves the root of the DocStore’s subtree.

Returns Error::NotFound if any part of the path does not exist, or if the final value is a tombstone (Value::Deleted). Returns Error::Io with ErrorKind::InvalidData if a non-map value is encountered during path traversal where a map was expected.

Source

pub async fn set(&self, value: Value) -> Result<()>

Sets a Value at the path specified by self.keys within the DocStore’s Transaction.

This method modifies the local data associated with the Transaction. The changes are not persisted to the backend until Transaction::commit() is called. If the path specified by self.keys does not exist, it will be created. Intermediate non-map values in the path will be overwritten by maps as needed. If self.keys is empty (editor points to root), the provided value must be a Value::Doc.

Returns Error::InvalidOperation if setting the root and value is not a node.

Source

pub async fn get_value(&self, key: impl AsRef<str>) -> Result<Value>

Returns a nested value by appending key to the current editor’s path.

This is a convenience method that uses self.get() to find the map at the current editor’s path, and then retrieves key from that map.

Source

pub fn get_value_mut(&self, key: impl Into<String>) -> ValueEditor<'a>

Constructs a new ValueEditor for a path one level deeper.

The new editor’s path will be self.keys with key appended.

Source

pub async fn delete_self(&self) -> Result<()>

Marks the value at the editor’s current path as deleted. This is achieved by setting its value to Value::Deleted. The change is staged in the Transaction and needs to be committed.

Source

pub async fn delete_child(&self, key: impl Into<String>) -> Result<()>

Marks the value at the specified child key (relative to the editor’s current path) as deleted. This is achieved by setting its value to Value::Deleted. The change is staged in the Transaction and needs to be committed.

If the editor points to the root (empty path), this will delete the top-level key.

Auto Trait Implementations§

§

impl<'a> Freeze for ValueEditor<'a>

§

impl<'a> !RefUnwindSafe for ValueEditor<'a>

§

impl<'a> Send for ValueEditor<'a>

§

impl<'a> Sync for ValueEditor<'a>

§

impl<'a> Unpin for ValueEditor<'a>

§

impl<'a> !UnwindSafe for ValueEditor<'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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more