Run fmt and clippy

This commit is contained in:
Gus Caplan
2019-05-28 09:52:44 -05:00
parent dfcaabc738
commit 2cc40a27d2
9 changed files with 84 additions and 64 deletions

View File

@ -10,11 +10,19 @@ pub struct JsArgument {
impl JsArgument {
fn required(name: String, type_: String) -> Self {
Self { optional: false, name, type_ }
Self {
optional: false,
name,
type_,
}
}
fn optional(name: String, type_: String) -> Self {
Self { optional: true, name, type_ }
Self {
optional: true,
name,
type_,
}
}
}
@ -237,7 +245,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}
if arg.is_anyref() {
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), "any".to_string()));
if self.cx.config.anyref {
if optional {
self.cx.expose_add_to_anyref_table()?;
@ -387,7 +396,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}
if let Some(s) = arg.rust_struct() {
self.js_arguments.push(JsArgument::required(name.clone(), s.to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), s.to_string()));
self.assert_class(&name, s);
self.assert_not_moved(&name);
if arg.is_by_ref() {
@ -401,7 +411,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}
if arg.number().is_some() {
self.js_arguments.push(JsArgument::required(name.clone(), "number".to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), "number".to_string()));
if self.cx.config.debug {
self.cx.expose_assert_num();
@ -419,7 +430,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.cx.expose_uint64_cvt_shim()
};
self.cx.expose_uint32_memory();
self.js_arguments.push(JsArgument::required(name.clone(), "BigInt".to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), "BigInt".to_string()));
self.prelude(&format!(
"
{f}[0] = {name};
@ -436,7 +448,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}
if arg.is_ref_anyref() {
self.js_arguments.push(JsArgument::required(name.clone(), "any".to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), "any".to_string()));
if self.cx.config.anyref {
self.anyref_args.push((self.rust_arguments.len(), false));
self.rust_arguments.push(name);
@ -469,7 +482,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.rust_arguments.push(format!("{}", name));
}
Descriptor::Char => {
self.js_arguments.push(JsArgument::required(name.clone(), "string".to_string()));
self.js_arguments
.push(JsArgument::required(name.clone(), "string".to_string()));
self.rust_arguments.push(format!("{}.codePointAt(0)", name))
}
_ => bail!(
@ -751,10 +765,12 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
let mut ret: String = self
.js_arguments
.iter()
.map(|a| if a.optional {
format!("@param {{{} | undefined}} {}\n", a.type_, a.name)
} else {
format!("@param {{{}}} {}\n", a.type_, a.name)
.map(|a| {
if a.optional {
format!("@param {{{} | undefined}} {}\n", a.type_, a.name)
} else {
format!("@param {{{}}} {}\n", a.type_, a.name)
}
})
.collect();
ret.push_str(&format!("@returns {{{}}}", self.ret_ty));

View File

@ -249,7 +249,12 @@ impl<'a> Context<'a> {
format!("{}{}\n", export, contents)
} else {
assert_eq!(export_name, definition_name);
format!("{}const {name} = {};\n__exports.{name} = {name};", export, contents, name = export_name)
format!(
"{}const {name} = {};\n__exports.{name} = {name};",
export,
contents,
name = export_name
)
}
}
};
@ -1163,8 +1168,7 @@ impl<'a> Context<'a> {
}}
}});
",
name,
name,
name, name,
));
}

View File

@ -731,8 +731,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
throw e;
}}\
",
&invoc,
shim,
&invoc, shim,
);
}

View File

@ -1,14 +1,14 @@
use std::fmt;
use std::pin::Pin;
use std::cell::{Cell, RefCell};
use std::sync::Arc;
use std::future::Future;
use std::task::{Poll, Context};
use std::collections::VecDeque;
use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use futures_util::task::ArcWake;
use futures_util::future::FutureExt;
use futures_channel::oneshot;
use futures_util::future::FutureExt;
use futures_util::task::ArcWake;
use lazy_static::lazy_static;
@ -112,14 +112,12 @@ where
Promise::new(&mut |resolve, reject| {
// TODO change Promise::new to be FnOnce
spawn_local(future.take().unwrap_throw().map(move |val| {
match val {
Ok(val) => {
resolve.call1(&JsValue::undefined(), &val).unwrap_throw();
},
Err(val) => {
reject.call1(&JsValue::undefined(), &val).unwrap_throw();
},
spawn_local(future.take().unwrap_throw().map(move |val| match val {
Ok(val) => {
resolve.call1(&JsValue::undefined(), &val).unwrap_throw();
}
Err(val) => {
reject.call1(&JsValue::undefined(), &val).unwrap_throw();
}
}));
})
@ -147,7 +145,10 @@ where
impl Task {
#[inline]
fn new<F>(future: F) -> Arc<Self> where F: Future<Output = ()> + 'static {
fn new<F>(future: F) -> Arc<Self>
where
F: Future<Output = ()> + 'static,
{
Arc::new(Self {
future: RefCell::new(Some(Box::pin(future))),
is_queued: Cell::new(false),
@ -171,7 +172,6 @@ where
}
}
struct NextTick {
is_spinning: Cell<bool>,
promise: Promise,
@ -180,7 +180,10 @@ where
impl NextTick {
#[inline]
fn new<F>(mut f: F) -> Self where F: FnMut() + 'static {
fn new<F>(mut f: F) -> Self
where
F: FnMut() + 'static,
{
Self {
is_spinning: Cell::new(false),
promise: Promise::resolve(&JsValue::null()),
@ -205,7 +208,6 @@ where
}
}
struct Executor {
// This is a queue of Tasks which will be polled in order
tasks: RefCell<VecDeque<Arc<Task>>>,
@ -265,6 +267,5 @@ where
};
}
ArcWake::wake_by_ref(&Task::new(future));
}