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§
Sourcefn apply_operation(
&mut self,
op: &GenericPatchOperation<Self>,
) -> Result<(), PatchError>
fn apply_operation( &mut self, op: &GenericPatchOperation<Self>, ) -> Result<(), PatchError>
Sourcefn get_mut_at_path(&mut self, path: &str) -> Result<&mut Self, PatchError>
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.
Sourcefn get_at_path(&self, path: &str) -> Result<&Self, PatchError>
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.
Sourcefn set_at_path(&mut self, path: &str, value: Self) -> Result<(), PatchError>
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.
Sourcefn remove_at_path(&mut self, path: &str) -> Result<Self, PatchError>
fn remove_at_path(&mut self, path: &str) -> Result<Self, PatchError>
Provided Methods§
Sourcefn apply_patch(&mut self, patch: &GenericPatch<Self>) -> Result<(), PatchError>
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.