Expand description
daybridge runtime (docs/bridge.md, DESIGN.md §15.6): foreign-language implementations of a Rust API.
A crate declares one API and supplies implementations per platform; day build generates the
adapters and the glue. This crate is the small runtime half: the bridge! macro, the
Error that crosses every boundary, the Support an arm reports, and the callback tier
(Done, Registry and Completion) that lets an arm answer after it has returned.
ⓘ
day_bridge::bridge! {
#[day_bridge::declare]
extern "day" {
fn speak_native(text: &str, done: day_bridge::Done<bool>) -> Result<(), day_bridge::Error>;
}
#[day_bridge::impl(rust, platforms = [other])]
fn speak_native(_text: &str, done: day_bridge::Done<bool>) -> Result<(), day_bridge::Error> {
done.complete(Err(day_bridge::Error::Unsupported));
Ok(())
}
}The generator is day_build::bridge, called from the crate’s
build.rs. Nothing here parses anything: see bridge! for why.
Macros§
- bridge
- Declare a crate’s bridge: the API and its per-platform implementations.
Structs§
- Completion
- The awaitable form of a
Donedeclaration: what a generated<fn>_futurereturns. - Done
- One outstanding completion, handed to an arm. A Rust arm calls
Done::complete; a foreign arm receivesDone::tokenand completes through the generated symbol. - Emit
- One open stream, handed to an arm. A Rust arm calls
Emit::emitand thenEmit::endorEmit::fail; a foreign arm receivesEmit::tokenand delivers through the generated<fn>_emit/<fn>_end/<fn>_failhelpers. - Registry
- The closures waiting on one declared function’s completions, keyed by token. The generator
emits one
staticperDonedeclaration; a foreign arm receives the token and the generated completion export resolves it here. - Streams
- The consumers of one
Emit<T>declaration’s streams, keyed by token: the stream counterpart ofRegistry. The generator emits onestaticper declaration.
Enums§
- Error
- The single error type crossing a bridge boundary (docs/bridge.md “Errors”).
- Item
- One delivery on an
Emit<T>stream: a value, the end, or a failure. The last two are terminal: nothing is delivered after either. - Support
- What a target’s arm promises, re-exported from day-spec so a bridged crate’s
available()answers in the same vocabulary asday::capability(). How fully a platform provides something a caller asks about.
Functions§
- guard
- Run a generated completion export’s body with panics contained: the export is called from C, the JVM, or the browser, and a panic unwinding into any of them is fatal.
- start_
async - Start a
Donecall in callback form: what a generated<fn>_asyncdoes. - start_
future - Start a
Donecall in future form: what a generated<fn>_futuredoes. - start_
stream - Start an
Emitcall: what a generated<fn>_streamdoes.cbreceives every item, in order, from whichever thread the platform delivers on. When the arm fails to start,cbreceives that failure (once) and this returns it.Okcarries the token a stop call takes.