Skip to content

refactor: use MaybeSend/MaybeSync on registry traits#35

Merged
alukach merged 1 commit into
refactor/simplify-cf-workersfrom
refactor/maybe-send-registry
May 21, 2026
Merged

refactor: use MaybeSend/MaybeSync on registry traits#35
alukach merged 1 commit into
refactor/simplify-cf-workersfrom
refactor/maybe-send-registry

Conversation

@alukach
Copy link
Copy Markdown
Member

@alukach alukach commented Apr 16, 2026

Summary

  • Changes BucketRegistry and CredentialRegistry trait bounds from Send + Sync to MaybeSend + MaybeSync
  • Changes future return bounds from + Send to + MaybeSend
  • Allows WASM implementations to use !Send types (like worker::Fetch and the CF Cache API) directly

This eliminates the painful spawn_local + oneshot channel bridge pattern that every CF Workers consumer must use when implementing these traits.

Test plan

  • cargo test passes (all native tests)
  • cargo check --target wasm32-unknown-unknown -p multistore-cf-workers passes

🤖 Generated with Claude Code

…istry

This allows WASM implementations to use !Send types (like worker::Fetch
and the CF Cache API) directly, eliminating the need for spawn_local +
oneshot channel bridges.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alukach alukach merged commit 63496dd into refactor/simplify-cf-workers May 21, 2026
8 of 12 checks passed
@alukach alukach deleted the refactor/maybe-send-registry branch May 21, 2026 05:05
alukach added a commit that referenced this pull request May 21, 2026
* feat(cf-workers): add RequestParts for ergonomic request extraction

Introduces RequestParts struct that extracts owned HTTP metadata from a
web_sys::Request and provides as_request_info() to borrow it for gateway
dispatch. Eliminates 8 lines of manual parsing boilerplate per handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(cf-workers): trim public exports to essential API surface

Reduce public exports from 8 to 2 (response_from_gateway, headermap_from_js).
Remove dead code (xml_response, s3_error_response) and make internal helpers
pub(crate).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(cf-workers): add WsHeaders newtype for ergonomic header conversion

Introduces WsHeaders wrapper around web_sys::Headers with From<&HeaderMap>,
working around orphan rule constraints. Replaces 4 manual header conversion
blocks in backend.rs and response.rs, and removes the now-unused headers_to_js.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(cf-workers): encapsulate JsBody with private field and accessor methods

Makes JsBody's inner Option<ReadableStream> private to prevent accidental
mutation. Adds JsBody::new() constructor and stream() accessor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(cf-workers): replace response_from_gateway with GatewayResponseExt trait

Replaces the free function with an extension trait on GatewayResponse,
enabling method syntax: `result.into_web_sys()`. Improves discoverability
via IDE autocomplete on the GatewayResponse type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: update crate-layout to reflect cf-workers ergonomic improvements

Documents RequestParts, GatewayResponseExt, JsBody, and WsHeaders in the
cf-workers crate description.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: add .worktrees to gitignore

* refactor: make Body an associated type on ProxyBackend (#38)

Replaces the generic Body parameter on forward() with an associated
type, eliminating runtime downcasts via Box<dyn Any>. Body type
mismatches are now caught at compile time.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(cf-workers): add CORS utility and auto-decode request paths (#37)

- add_cors_headers() sets permissive CORS headers for browser-accessible
  S3-compatible read-only proxies
- RequestParts::from_web_sys() now percent-decodes the URL path
  automatically

These eliminate two common boilerplate patterns in consumer apps.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add HandlerAction::response_headers_mut() for ergonomic header injection (#36)

Middleware that adds response headers (CORS, Server-Timing, etc.) no
longer needs to match on all three HandlerAction variants manually.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: use MaybeSend/MaybeSync on BucketRegistry and CredentialRegistry (#35)

This allows WASM implementations to use !Send types (like worker::Fetch
and the CF Cache API) directly, eliminating the need for spawn_local +
oneshot channel bridges.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: merge fix

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant