Closed
Description
How would I call [chrome.tabs.query] to get back an array of tabs. I'm struggling to write the interop for this.
https://developer.chrome.com/extensions/tabs#method-query
http://definitelytyped.org/docs/chrome--chrome/interfaces/chrome.tabs.tab.html
I created a module named chrome_tabs.rs
and it currently has:
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct QueryInfo {
pub active: Option<bool>
}
#[wasm_bindgen]
pub struct Tab {
pub active: bool,
pub id: u32,
}
#[wasm_bindgen(module = "chrome.tabs")]
extern "C" {
pub fn query(query_info: QueryInfo, callback: &Fn([&Tab]));
}
Errors with:
error[E0277]: the trait bound `&dyn for<'r> std::ops::Fn([&'r chrome_tabs::Tab]): wasm_bindgen::convert::traits::IntoWasmAbi` is not satisfied
--> src/chrome_tabs.rs:19:1
|
19 | #[wasm_bindgen(module = "chrome.tabs")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::traits::IntoWasmAbi` is not implemented for `&dyn for<'r> std::ops::Fn([&'r chrome_tabs::Tab])`
|
= help: the following implementations were found:
<&'a (dyn for<'r> std::ops::Fn(&'r A) -> R + 'b) as wasm_bindgen::convert::traits::IntoWasmAbi>
<&'a (dyn std::ops::Fn() -> R + 'b) as wasm_bindgen::convert::traits::IntoWasmAbi>
<&'a (dyn std::ops::Fn(A) -> R + 'b) as wasm_bindgen::convert::traits::IntoWasmAbi>
<&'a (dyn std::ops::Fn(A, B) -> R + 'b) as wasm_bindgen::convert::traits::IntoWasmAbi>
and 6 others
I'm using nightly because I was looking at
wasm-bindgen/tests/wasm/closures.rs
Lines 475 to 491 in 8ba0142
wasm-bindgen = { version = "0.2.55", features = ["serde-serialize","nightly"] }
If I do not make Tab a reference, then I get this error:
error[E0277]: the trait bound `[chrome_tabs::Tab]: wasm_bindgen::convert::traits::FromWasmAbi` is not satisfied
--> src/chrome_tabs.rs:29:41
|
29 | pub fn query(query_info: QueryInfo, callback: &Fn([Tab]));
| ^^^^^^^^ the trait `wasm_bindgen::convert::traits::FromWasmAbi` is not implemented for `[chrome_tabs::Tab]`
|
= note: required because of the requirements on the impl of `wasm_bindgen::convert::traits::IntoWasmAbi` for `&dyn std::ops::Fn([chrome_tabs::Tab])`