Add JsCast to wasm_bindgen::prelude (#3221)

* Add `JsCast` to `wasm_bindgen::prelude`

`JsCast` is a very commonly used trait, but for some reason has never been added to `wasm_bindgen::prelude`, leading to the constant annoyance of having to manually import it.

* Remove redundant imports
This commit is contained in:
Liam Murphy 2023-01-04 02:44:23 +11:00 committed by GitHub
parent ee89f9051e
commit a10e949127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 6 additions and 50 deletions

View File

@ -2,7 +2,6 @@ extern crate wasm_bindgen;
extern crate web_sys;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::Node;
#[wasm_bindgen(raw_module = "../globals.js")]

View File

@ -11,7 +11,7 @@ use core::pin::Pin;
use core::task::{Context, Poll};
use futures_core::stream::Stream;
use js_sys::{AsyncIterator, IteratorNext};
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen::prelude::*;
/// A `Stream` that yields values from an underlying `AsyncIterator`.
pub struct JsStream {

View File

@ -8,7 +8,6 @@ use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
const SLEEPING: i32 = 0;
const AWAKE: i32 = 1;

View File

@ -40,7 +40,6 @@ use js_sys::{encode_uri_component, Array, Promise};
use std::cell::RefCell;
use std::sync::atomic::AtomicI32;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{MessageEvent, Worker};
const HELPER_CODE: &'static str = "

View File

@ -5,7 +5,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use futures_channel::oneshot;
use js_sys::Promise;
use std::ops::FnMut;
use wasm_bindgen::{prelude::*, JsValue};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::{future_to_promise, spawn_local, JsFuture};
use wasm_bindgen_test::*;
@ -138,7 +138,6 @@ async fn can_create_multiple_futures_from_same_promise() {
#[wasm_bindgen_test]
async fn can_use_an_async_iterable_as_stream() {
use futures_lite::stream::StreamExt;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::stream::JsStream;
let async_iter = js_sys::Function::new_no_args(

View File

@ -29,7 +29,6 @@ use std::str;
use std::str::FromStr;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
// When adding new imports:
//

View File

@ -1,8 +1,6 @@
use js_sys::*;
use std::iter::FromIterator;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
macro_rules! js_array {

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]

View File

@ -1,7 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/JsString.js")]

View File

@ -2,7 +2,6 @@ use std::f64::{INFINITY, NAN};
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/Number.js")]

View File

@ -1,7 +1,6 @@
use js_sys::*;
use std::f64::NAN;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen]

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
fn set2vec(s: &Set) -> Vec<JsValue> {

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/SharedArrayBuffer.js")]

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/Temporal.js")]

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
macro_rules! each {

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen]

View File

@ -1,6 +1,5 @@
use js_sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen]

View File

@ -1,5 +1,5 @@
use js_sys::*;
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::{Headers, Response, ResponseInit};

View File

@ -1,7 +1,6 @@
//! Runtime detection of whether we're in node.js or a browser.
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
#[wasm_bindgen]
extern "C" {

View File

@ -1,6 +1,5 @@
use js_sys::{Array, ArrayBuffer};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::Blob;

View File

@ -1,6 +1,5 @@
use js_sys::{Object, Promise};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::Event;

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
use web_sys::HtmlElement;

View File

@ -1,6 +1,5 @@
use js_sys::{ArrayBuffer, DataView, Object, Promise, Reflect, WebAssembly};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::{Headers, Response, ResponseInit};

View File

@ -1,4 +1,4 @@
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;

View File

@ -1,6 +1,5 @@
use crate::generated::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
macro_rules! read_test_suite {

View File

@ -1,7 +1,6 @@
use crate::generated::*;
use js_sys::Object;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]

View File

@ -1,6 +1,5 @@
use std::f64;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
#[wasm_bindgen(start)]
pub fn start() {

View File

@ -1,6 +1,5 @@
use js_sys::{Array, Date};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{Document, Element, HtmlElement, Window};
#[wasm_bindgen(start)]

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::{Request, RequestInit, RequestMode, Response};

View File

@ -1,7 +1,6 @@
use std::cell::Cell;
use std::rc::Rc;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
#[wasm_bindgen(start)]
pub fn start() -> Result<(), JsValue> {

View File

@ -2,7 +2,6 @@ use futures_channel::oneshot;
use js_sys::{Promise, Uint8ClampedArray, WebAssembly};
use rayon::prelude::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
macro_rules! console_log {
($($t:tt)*) => (crate::log(&format_args!($($t)*).to_string()))

View File

@ -8,7 +8,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{DedicatedWorkerGlobalScope, MessageEvent};
use web_sys::{ErrorEvent, Event, Worker};

View File

@ -1,7 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
fn window() -> web_sys::Window {
web_sys::window().expect("no global `window` exists")

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::EventTarget;
/// Wrapper for `web_sys::Element` to simplify calling different interfaces

View File

@ -5,7 +5,6 @@ use crate::store::ItemList;
use crate::{Message, Scheduler};
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen::JsCast;
use crate::template::Template;

View File

@ -1,6 +1,5 @@
use js_sys::{Function, Map, Object, Reflect, WebAssembly};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::{spawn_local, JsFuture};
#[wasm_bindgen]

View File

@ -1,6 +1,5 @@
use js_sys::{Function, Object, Reflect, WebAssembly};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::{spawn_local, JsFuture};
// lifted from the `console_log` example

View File

@ -1,7 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{console, HtmlElement, HtmlInputElement, MessageEvent, Worker};
/// A number evaluation struct

View File

@ -8,7 +8,6 @@ use std::time::{Duration, UNIX_EPOCH};
use gloo::events::EventListener;
use json::JsonValue;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::spawn_local;
use web_sys::Document;
use web_sys::Element;

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{WebGl2RenderingContext, WebGlProgram, WebGlShader};
#[wasm_bindgen(start)]

View File

@ -1,6 +1,5 @@
use js_sys::Reflect;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::{
MessageEvent, RtcDataChannelEvent, RtcPeerConnection, RtcPeerConnectionIceEvent, RtcSdpType,

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{ErrorEvent, MessageEvent, WebSocket};
macro_rules! console_log {

View File

@ -8,7 +8,6 @@ use std::cell::RefCell;
use std::rc::Rc;
use utils::set_panic_hook;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::future_to_promise;
use web_sys::*;

View File

@ -50,6 +50,7 @@ macro_rules! externs {
/// use wasm_bindgen::prelude::*;
/// ```
pub mod prelude {
pub use crate::JsCast;
pub use crate::JsValue;
pub use crate::UnwrapThrowExt;
#[doc(hidden)]

View File

@ -1,6 +1,5 @@
use js_sys::{Uint8Array, WebAssembly};
use wasm_bindgen::prelude::*;
use wasm_bindgen::{self, JsCast};
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/api.js")]

View File

@ -493,7 +493,6 @@ fn test_closure_returner() {
type ClosureType = dyn FnMut() -> BadStruct;
use js_sys::{Object, Reflect};
use wasm_bindgen::JsCast;
js_test_closure_returner();

View File

@ -1,5 +1,4 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/jscast.js")]

View File

@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen::{intern, unintern, JsCast};
use wasm_bindgen::{intern, unintern};
use wasm_bindgen_test::*;
#[wasm_bindgen(module = "tests/wasm/simple.js")]