Skip to main content

Patchable

Trait Patchable 

Source
pub trait Patchable: Sized + DiffableValue {
    // Required methods
    fn apply_operation(
        &mut self,
        op: &GenericPatchOperation<Self>,
    ) -> Result<(), PatchError>;
    fn get_mut_at_path(&mut self, path: &str) -> Result<&mut Self, PatchError>;
    fn get_at_path(&self, path: &str) -> Result<&Self, PatchError>;
    fn set_at_path(&mut self, path: &str, value: Self) -> Result<(), PatchError>;
    fn remove_at_path(&mut self, path: &str) -> Result<Self, PatchError>;

    // Provided method
    fn apply_patch(
        &mut self,
        patch: &GenericPatch<Self>,
    ) -> Result<(), PatchError> { ... }
}
Expand description

Trait for values that can have patches applied

This trait extends DiffableValue with mutation capabilities needed for applying patch operations like add, remove, replace, move, and copy.

§Implementation Notes

  • Navigation methods should handle JSON Pointer syntax (RFC 6901)
  • Mutations should be atomic when possible
  • Test operations should not modify the value

Required Methods§

Source

fn apply_operation( &mut self, op: &GenericPatchOperation<Self>, ) -> Result<(), PatchError>

Apply a single patch operation

§Errors

Returns an error if the operation cannot be applied.

Source

fn get_mut_at_path(&mut self, path: &str) -> Result<&mut Self, PatchError>

Navigate to a path and return a mutable reference

§Errors

Returns an error if the path doesn’t exist or is invalid.

Source

fn get_at_path(&self, path: &str) -> Result<&Self, PatchError>

Navigate to a path and return an immutable reference

§Errors

Returns an error if the path doesn’t exist or is invalid.

Source

fn set_at_path(&mut self, path: &str, value: Self) -> Result<(), PatchError>

Set a value at a path (creating intermediate containers as needed)

§Errors

Returns an error if the path is invalid.

Source

fn remove_at_path(&mut self, path: &str) -> Result<Self, PatchError>

Remove a value at a path

§Errors

Returns an error if the path doesn’t exist.

Provided Methods§

Source

fn apply_patch(&mut self, patch: &GenericPatch<Self>) -> Result<(), PatchError>

Apply an entire patch

Operations are applied in order. If any operation fails, the value may be in a partially modified state.

§Errors

Returns an error if any operation fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Patchable for Value

Source§

fn apply_operation( &mut self, op: &GenericPatchOperation<Value>, ) -> Result<(), PatchError>

Source§

fn get_mut_at_path(&mut self, path: &str) -> Result<&mut Value, PatchError>

Source§

fn get_at_path(&self, path: &str) -> Result<&Value, PatchError>

Source§

fn set_at_path(&mut self, path: &str, value: Value) -> Result<(), PatchError>

Source§

fn remove_at_path(&mut self, path: &str) -> Result<Value, PatchError>

Implementors§