| Crates.io | openworkers-glue-v8 |
| lib.rs | openworkers-glue-v8 |
| version | 0.4.0 |
| created_at | 2026-01-17 17:48:50.176212+00 |
| updated_at | 2026-01-18 11:50:46.225266+00 |
| description | V8 Glue - Rust to V8 binding macros for OpenWorkers |
| homepage | |
| repository | https://github.com/openworkers/glue-v8 |
| max_upload_size | |
| id | 2050856 |
| size | 94,927 |
Proc-macro crate that generates V8 callback boilerplate from Rust functions.
use std::rc::Rc;
// Basic function
#[gv8::method]
fn add(_scope: &mut v8::PinScope, a: f64, b: f64) -> f64 {
a + b
}
// With state from context slot
#[gv8::method(state = Rc<MyState>)]
fn get_count(_scope: &mut v8::PinScope, state: &Rc<MyState>) -> i32 {
state.count.get()
}
// With Result (Err throws JS exception)
#[gv8::method]
fn parse(_scope: &mut v8::PinScope, input: String) -> Result<f64, String> {
input.parse().map_err(|e| format!("{}", e))
}
// With Promise (returns JS Promise)
#[gv8::method(promise)]
fn async_op(_scope: &mut v8::PinScope, val: i32) -> Result<i32, String> {
if val > 0 { Ok(val * 2) } else { Err("must be positive".into()) }
}
// Optional parameters
#[gv8::method]
fn greet(_scope: &mut v8::PinScope, name: String, title: Option<String>) -> String {
match title {
Some(t) => format!("{} {}", t, name),
None => name,
}
}
The macro generates a {fn_name}_v8 wrapper function that:
FunctionCallbackArgumentsserde_v8Parameters:
i32, u32, f64, bool, StringOption<T> (None for undefined/null/missing)v8::Local<v8::Function>, v8::Local<v8::Uint8Array>, etc.serde::DeserializeReturn types:
StringResult<T, E> (Err throws exception)serde::SerializeAttributes:
state = Rc<T> - Extract state from context slotpromise - Return a JS Promisename = "jsName" - Custom JS function namecargo test