Skip to content

Remove explicit ::wit_bindgen_rt import from async support #1135

@rvolosatovs

Description

@rvolosatovs

Currently wit-bindgen explicitly imports ::wit_bindgen_rt for async, e.g.:

if !self.future_payloads.is_empty() {
self.src.push_str(
"\
pub mod wit_future {
#![allow(dead_code, unused_variables, clippy::all)]
#[doc(hidden)]
pub trait FuturePayload: Unpin + Sized + 'static {
fn new() -> (u32, &'static ::wit_bindgen_rt::async_support::FutureVtable<Self>);
}",
);
for code in self.future_payloads.values() {
self.src.push_str(code);
}
self.src.push_str(
"\
/// Creates a new Component Model `future` with the specified payload type.
pub fn new<T: FuturePayload>() -> (::wit_bindgen_rt::async_support::FutureWriter<T>, ::wit_bindgen_rt::async_support::FutureReader<T>) {
let (handle, vtable) = T::new();
::wit_bindgen_rt::async_support::with_entry(handle, |entry| match entry {
::std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(::wit_bindgen_rt::async_support::Handle::LocalOpen);
}
::std::collections::hash_map::Entry::Occupied(_) => unreachable!(),
});
(
::wit_bindgen_rt::async_support::FutureWriter::new(handle, vtable),
::wit_bindgen_rt::async_support::FutureReader::new(handle, vtable),
)
}
}
",
);
}
if !self.stream_payloads.is_empty() {
self.src.push_str(
"\
pub mod wit_stream {
#![allow(dead_code, unused_variables, clippy::all)]
pub trait StreamPayload: Unpin + Sized + 'static {
fn new() -> (u32, &'static ::wit_bindgen_rt::async_support::StreamVtable<Self>);
}",
);
for code in self.stream_payloads.values() {
self.src.push_str(code);
}
self.src.push_str(
"\
/// Creates a new Component Model `stream` with the specified payload type.
pub fn new<T: StreamPayload>() -> (::wit_bindgen_rt::async_support::StreamWriter<T>, ::wit_bindgen_rt::async_support::StreamReader<T>) {
let (handle, vtable) = T::new();
::wit_bindgen_rt::async_support::with_entry(handle, |entry| match entry {
::std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(::wit_bindgen_rt::async_support::Handle::LocalOpen);
}
::std::collections::hash_map::Entry::Occupied(_) => unreachable!(),
});
(
::wit_bindgen_rt::async_support::StreamWriter::new(handle, vtable),
::wit_bindgen_rt::async_support::StreamReader::new(handle, vtable),
)
}
}
",
);
}
}

Instead, it should import from the configured runtime module path, which is normally re-exported by wit-bindgen

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions