Skip to content

Remove redundant Clone bound from Patchable::Patch and make derivations optional #33

@ShapelessCat

Description

@ShapelessCat

Current Implementation

Currently, the Patchable trait enforces a Clone bound on its associated Patch type:

pub trait Patchable: Sized {
    /// The type of patch associated with this structure.
    type Patch: Clone;
}

Proposed Changes

We should remove the mandatory Clone bound to increase the library's flexibility. While Clone was useful in the original design context, it is not strictly necessary for the core logic of patching.

  1. Trait Refactor
    Remove the : Clone requirement from the Patch associated type.

  2. Macro Enhancements (patchable-macro)
    Update the procedural macro to allow optional derivation of Clone (TODO) and serde's Serialize and Deserialize (DONE before this issue creation). We should introduce a new feature flag to manage this:

    • Feature: cloneable — Controls whether the generated patch type derives Clone.

    • Default Features: Both cloneable and serde should remain in default.

Rationale

Why make Clone and Serde derivations optional?

The original implementation was designed for durable computation, where checkpoints required state persistence. In that specific context:

  • Clone: We assumed patch types would always be cloneable. However, this was largely used for testing rather than core functionality. For a general-purpose library, a Patch should be able to be any type, including those that are not (or should not be) cloneable.

  • Serde: Similarly, while saving state to disk and loading from disk is vital for durable computation, many other use cases do not require serialization/deserialization

By moving these into feature flags, we allow users to opt-out of these dependencies and derivations, reducing compile times and keeping the generated code lean for non-durable-computation scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions