mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-02 21:25:16 +03:00
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:
parent
ee89f9051e
commit
a10e949127
@ -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")]
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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 = "
|
||||
|
@ -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(
|
||||
|
@ -29,7 +29,6 @@ use std::str;
|
||||
use std::str::FromStr;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
// When adding new imports:
|
||||
//
|
||||
|
@ -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 {
|
||||
|
@ -1,6 +1,5 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
|
@ -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")]
|
||||
|
@ -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")]
|
||||
|
@ -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]
|
||||
|
@ -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> {
|
||||
|
@ -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")]
|
||||
|
@ -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")]
|
||||
|
@ -1,6 +1,5 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
macro_rules! each {
|
||||
|
@ -1,6 +1,5 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -1,6 +1,5 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -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};
|
||||
|
@ -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" {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
use web_sys::HtmlElement;
|
||||
|
||||
|
@ -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};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::generated::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
macro_rules! read_test_suite {
|
||||
|
@ -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]
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::f64;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn start() {
|
||||
|
@ -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)]
|
||||
|
@ -1,5 +1,4 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::{Request, RequestInit, RequestMode, Response};
|
||||
|
||||
|
@ -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> {
|
||||
|
@ -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()))
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{WebGl2RenderingContext, WebGlProgram, WebGlShader};
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,4 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{ErrorEvent, MessageEvent, WebSocket};
|
||||
|
||||
macro_rules! console_log {
|
||||
|
@ -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::*;
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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")]
|
||||
|
@ -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();
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen(module = "tests/wasm/jscast.js")]
|
||||
|
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user