foreign-runtime/crossing/src/main.nika

// A compiler experiment, expected to be refused: a value that must stay on one
// thread is handed to a Rust library that runs it on a thread of its own.
//
//     cd examples/foreign-runtime/crossing
//     nikaia build
//     error[NK2502]: `handle` may not cross a thread, and
//     `hyper_shim::across_a_thread` may put it on one
//
// The first build fetches `hyper` and `tokio` from crates.io.
//
// It checks that the refusal comes from this compiler, in its own words, at
// this file's line, and not from `rustc` in generated code. The value comes
// from the Rust side because a Nikaia value cannot be built into this shape.
// What decides it is the crate's description in `contracts/`: `LocalHandle`
// may not cross a thread, and `across_a_thread` starts one.

fn main() {
    let handle = hyper_shim::local_handle("not Send")
    let crossed = hyper_shim::across_a_thread(handle)
    println(f"crossed: {crossed}")
}

The file itself · all the examples

This site is open source. Improve this page.