Skip to content

Introduce builders for the storage implementations - #260

Draft
Alnusjaponica wants to merge 2 commits into
mainfrom
feat/storage-builder
Draft

Alnusjaponica wants to merge 2 commits into
mainfrom
feat/storage-builder

Conversation

@Alnusjaponica

@Alnusjaponica Alnusjaponica commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the XxxStorageOptions/new_with_option(s) construction pattern with builders following the API style of std::thread::Builder: settings are configured by chaining setter methods and the storage is created with build. As with thread::Builder::new(), XxxBuilder::new() is the only entry point (consistent with PedAnovaBuilder in #262).

let storage = InMemoryStorageBuilder::new()
    .apply_discard(true)
    .attr_format(AttrFormat::Json)
    .build();

let storage = SQLite3StorageBuilder::new(file_path)
    .apply_discard(true)
    .build()?;   // Result

let storage = JournalStorageBuilder::new(Box::new(backend))
    .apply_discard(true)
    .build()?;   // Result

Changes

  • Add InMemoryStorageBuilder (with Default), SQLite3StorageBuilder, and JournalStorageBuilder, exposing new(), chainable setters (apply_discard, attr_format), and build()
  • Remove InMemoryStorageOptions, SQLite3StorageOptions, JournalStorageOptions and new_with_option/new_with_options
  • Keep new on InMemoryStorage/SQLite3Storage/JournalStorage with the existing signatures; it now delegates to the builders
  • Update the pyo3 bindings (including ToRustStorage's cache) to construct storages through the builders
  • Update a doc comment in cache.rs that referenced the removed options structs

Verification

  • cargo test --locked --all-features — all pass (including new doctests)
  • cargo test --locked -- --ignored (from rustuna_storage, with Optuna installed) — 6 pass
  • cargo clippy --locked --workspace --lib --bins --tests --examples --all-features -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • Python: uv run --no-sync pytest tests/ — 706 passed, 16 skipped

🤖 Generated with Claude Code

Replace the `XxxStorageOptions`/`new_with_option(s)` construction pattern
with builders following the API style of `std::thread::Builder`: settings
are configured by chaining setter methods and the storage is created with
`build`.

- `InMemoryStorageBuilder`: `InMemoryStorage::builder().apply_discard(true).build()`
- `SQLite3StorageBuilder`: `SQLite3Storage::builder(file_path).apply_discard(true).build()`
- `JournalStorageBuilder`: `JournalStorage::builder(backend).apply_discard(true).build()`

`InMemoryStorageOptions`, `SQLite3StorageOptions`, `JournalStorageOptions`
and `new_with_option`/`new_with_options` are removed. `new` is kept for
backward compatibility and now delegates to the builders. The pyo3 bindings
construct storages through the builders as well.
@Alnusjaponica
Alnusjaponica marked this pull request as draft September 28, 2026 02:21
@c-bata c-bata self-assigned this Oct 5, 2026
@c-bata

c-bata commented Oct 5, 2026

Copy link
Copy Markdown
Member

@Alnusjaponica Is this PR ready for review?

Resolve conflicts with main, which added `attr_format` to the storage
options, by adding an `attr_format` setter to each builder.

Following the decision in #262, `XxxBuilder::new()` is now the only entry
point (matching `std::thread::Builder::new()`); the `XxxStorage::builder()`
methods are removed.

- `InMemoryStorageBuilder::new().apply_discard(true).attr_format(..).build()`
- `SQLite3StorageBuilder::new(file_path).apply_discard(true).build()?`
- `JournalStorageBuilder::new(backend).apply_discard(true).build()?`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alnusjaponica
Alnusjaponica marked this pull request as ready for review November 4, 2026 10:06
@Alnusjaponica
Alnusjaponica marked this pull request as draft November 6, 2026 05:33
@c-bata c-bata removed their assignment Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants