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>
impl<'a> ValueEditor<'a>
pub fn new<K>(kv_store: &'a DocStore, keys: K) -> Self
Sourcepub async fn get(&self) -> Result<Value>
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.
Sourcepub async fn set(&self, value: Value) -> Result<()>
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.
Sourcepub async fn get_value(&self, key: impl AsRef<str>) -> Result<Value>
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.
Sourcepub fn get_value_mut(&self, key: impl Into<String>) -> ValueEditor<'a>
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.
Sourcepub async fn delete_self(&self) -> Result<()>
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.
Sourcepub async fn delete_child(&self, key: impl Into<String>) -> Result<()>
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> 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<T> CompatExt for T
impl<T> CompatExt for T
§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>
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 more