Skip to content

🛠️ Impl Collection#7

Merged
amimart merged 31 commits into
mainfrom
feat/impl-collection
Jun 1, 2026
Merged

🛠️ Impl Collection#7
amimart merged 31 commits into
mainfrom
feat/impl-collection

Conversation

@amimart

@amimart amimart commented Jun 1, 2026

Copy link
Copy Markdown
Owner

💡 Purpose

The PR brings the implementation of the core Collection API.

⚙️ Details

Here's the functions implemented:

  • collection::insert();
  • collection::update();
  • collection::save();
  • collection::remove();
  • collection::scan();

The arguments have been changed to borrowed values to avoid copy/clone.

The function's bodies are pretty basic, but some refactoring to allow zero-copy and zero-allocation behaviours were needed, especially concerning indexes traits, for instance regarding the Index::update() signature:

fn update<'a, DB: MultiStoreWriteHandle>(
        db: &mut DB,
        pk: &Record::Key<'a>,
        old: Option<&Record>,
        new: &'a Record,
    ) -> Result<(), Error>
    where
        for<'ik, 'pk> Self::Kind<'ik>: IndexKind<Self::Key<'ik>, Record::Key<'pk>>,

The main change here is the lifetime separation between the old record and the primary key, the reason lies in their provenance in the collection methods, for exemple with the update fn: The primary key is provided to collection::update() so its lifetime outlives its scope, but the old record is fetched in collection::update() so its lifetime is inferior to the primary key and the new value. This caused a necessary change in the indexKind::StoreKey<'ik, 'pk> to carry both lifetimes and thus, contaminating indexes api.

🧪 Testing

For testing purposes a mocked implementation of MultiStore has been introduced and allows to:

  • Provide static data already present;
  • Observes operations log;

@amimart amimart self-assigned this Jun 1, 2026
@amimart amimart marked this pull request as ready for review June 1, 2026 14:40
@amimart amimart merged commit 599e0db into main Jun 1, 2026
7 checks passed
@amimart amimart deleted the feat/impl-collection branch June 1, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant