Skip to content

Instantly share code, notes, and snippets.

View dicej's full-sized avatar

Joel Dice dicej

  • Denver, Colorado
View GitHub Profile
(func $App_SpinHttpWorld_wit_exports_wasi_http_v0_2_0_AppJsonSerializerContext__global__System_Text_Json_Serialization_Metadata_IJsonTypeInfoResolver_GetTypeInfo (;20990;) (type 6) (param i32 i32 i32
i32) (result i32)
(local i32)
block ;; label = @1
block ;; label = @2
block ;; label = @3
local.get 2
i32.const 2670040
i32.eq
br_if 0 (;@3;)
@dicej
dicej / snippets.rs
Created October 4, 2024 23:41
wasmtime-wit-bindgen lifetime fun
pub fn for_any<F, R, T>(fun: F) -> F
where
F: FnOnce(StoreContextMut<T>) -> R + 'static,
R: 'static,
{
fun
}
pub fn for_any_future<F, R, T, FF>(fut: FF) -> FF
where
@dicej
dicej / 001-current-handler.wit
Last active October 18, 2024 15:31
Async bindgen snippets
interface handler {
use types.{request, response, error-code};
handle: func(
request: request,
) -> result<response, error-code>;
}
@dicej
dicej / concurrent-bindgen-sketch.rs
Last active February 4, 2025 13:16
Sketch of alternative `wasmtime-wit-bindgen` `concurrent-imports` approach based on thread-local storage
// Somewhere in Wasmtime:
thread_local! {
static LOCAL_STORE: Cell<*mut dyn VMStore> = Cell::new(ptr::null_mut());
}
pub struct LocalStore<'a, T> {
// We only use `T` in the `with` method below.
_phatom_type: PhantomData<T>,
@dicej
dicej / snippets.rs
Last active February 19, 2025 16:34
wasmtime-wit-bindgen factors
thread_local! {
static FINISH_HOST: std::cell::Cell<*mut u8> = std::cell::Cell::new(std::ptr::null_mut());
static FINISH_SPAWNED: std::cell::RefCell<Vec<std::pin::Pin<Box<dyn std::future::Future<Output = wasmtime::component::HostTaskOutput> + Send + Sync + 'static>>>> = std::cell::RefCell::new(Vec::new());
}
fn poll<T, G: for<'a> GetHost<&'a mut T>, F: std::future::Future + ?Sized>(
getter: G,
store: wasmtime::VMStoreRawPtr,
cx: &mut std::task::Context,
future: std::pin::Pin<&mut F>,
@dicej
dicej / errors.wit
Created March 19, 2025 16:21
wasi-http errors
/// `request-write-result` will produce an error if the _caller_ has trouble writing
/// the request body or trailers.
///
/// The returned `future` will produce an error if the _callee_ has trouble writing
/// the response body or trailers.
handle: func(request: request, request-write-result: future<result<_, error-code>>)
-> result<tuple<response, future<result<_, error-code>>>, error-code>;
struct StoreToken<T> {
id: StoreId,
_phantom: PhantomData<fn() -> T>,
}
impl<T> StoreToken<T> {
pub fn new(store: StoreContextMut<T>) -> Self {
Self { id: store.id(), _phantom: PhantomData }
}