Skip to content

Document async FFI and error handling patterns in Rust AGENTS.md#6473

Merged
jasnell merged 1 commit intomainfrom
harris/2026-04-01-async-ffi-docs
Apr 1, 2026
Merged

Document async FFI and error handling patterns in Rust AGENTS.md#6473
jasnell merged 1 commit intomainfrom
harris/2026-04-01-async-ffi-docs

Conversation

@harrishancock
Copy link
Copy Markdown
Collaborator

I had trouble coaxing Claude to implement an async, Result-returning cxxbridged Rust function, because it doesn't know that our cxx-rs fork supports async interoperability, or KJ exceptions. I'm not sure where's best to put this, but this file seems reasonable.


Add guidance on how to declare async functions in extern "Rust" CXX bridge blocks (explicit lifetime + unsafe required), and how to handle errors across the FFI boundary (thiserror, std::io::Error, or cxx::KjError).

Assisted-by: Claude

@harrishancock harrishancock requested review from anonrig and mikea April 1, 2026 10:18
@harrishancock harrishancock requested review from a team as code owners April 1, 2026 10:18
Add guidance on how to declare async functions in extern "Rust"
CXX bridge blocks (explicit lifetime + unsafe required), and how
to handle errors across the FFI boundary (thiserror, std::io::Error,
or cxx::KjError).

Assisted-by: Claude
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 1, 2026

The documentation is accurate. The code examples in the PR match the real patterns in the codebase. Let me do a final check on one detail -- the extern "Rust" example uses self: &'a MyType whereas the actual code uses self: &'a mut DynHttpService. The doc example shows &self (non-mut) which is fine as a simplified illustration. And the extern "C++" example is a simplified version of the actual code at kj/http.rs:132-139, which is appropriate for documentation.

The documentation is concise, accurate, and well-structured. All the technical claims check out against the actual codebase and the workerd-cxx fork. This is purely a documentation change to an AGENTS.md file, so there are no backward compatibility, security, or runtime behavior concerns.

LGTM

github run

@harrishancock harrishancock force-pushed the harris/2026-04-01-async-ffi-docs branch from 2ca54e2 to 2a282a7 Compare April 1, 2026 10:23
@jasnell jasnell merged commit 7c64ff7 into main Apr 1, 2026
24 checks passed
@jasnell jasnell deleted the harris/2026-04-01-async-ffi-docs branch April 1, 2026 13:50
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.

3 participants