Skip to main content

Crate day_bridge

Crate day_bridge 

Source
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 Done declaration: what a generated <fn>_future returns.
Done
One outstanding completion, handed to an arm. A Rust arm calls Done::complete; a foreign arm receives Done::token and completes through the generated symbol.
Emit
One open stream, handed to an arm. A Rust arm calls Emit::emit and then Emit::end or Emit::fail; a foreign arm receives Emit::token and delivers through the generated <fn>_emit / <fn>_end / <fn>_fail helpers.
Registry
The closures waiting on one declared function’s completions, keyed by token. The generator emits one static per Done declaration; 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 of Registry. The generator emits one static per 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 as day::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 Done call in callback form: what a generated <fn>_async does.
start_future
Start a Done call in future form: what a generated <fn>_future does.
start_stream
Start an Emit call: what a generated <fn>_stream does. cb receives every item, in order, from whichever thread the platform delivers on. When the arm fails to start, cb receives that failure (once) and this returns it. Ok carries the token a stop call takes.