diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a85adb4a..bfff290e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,7 +86,7 @@ jobs: cargo-${{ runner.os }}- - name: Install `cargo-readme` - run: cargo install cargo-readme + run: which cargo-readme || cargo install cargo-readme - name: Test `README.md`s are up to date run: | diff --git a/crates/events/src/lib.rs b/crates/events/src/lib.rs index a888a997..d65d03cc 100644 --- a/crates/events/src/lib.rs +++ b/crates/events/src/lib.rs @@ -155,7 +155,7 @@ impl EventListenerOptions { } #[inline] - fn to_js(&self, once: bool) -> AddEventListenerOptions { + fn as_js(&self, once: bool) -> AddEventListenerOptions { let mut options = AddEventListenerOptions::new(); options.capture(self.phase.is_capture()); @@ -179,8 +179,8 @@ impl Default for EventListenerOptions { // This defaults passive to true to avoid performance issues in browsers: // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners thread_local! { - static NEW_OPTIONS: AddEventListenerOptions = EventListenerOptions::default().to_js(false); - static ONCE_OPTIONS: AddEventListenerOptions = EventListenerOptions::default().to_js(true); + static NEW_OPTIONS: AddEventListenerOptions = EventListenerOptions::default().as_js(false); + static ONCE_OPTIONS: AddEventListenerOptions = EventListenerOptions::default().as_js(true); } /// RAII type which is used to manage DOM event listeners. @@ -462,7 +462,7 @@ impl EventListener { target, event_type.into(), callback, - &options.to_js(false), + &options.as_js(false), options.phase, ) } @@ -526,7 +526,7 @@ impl EventListener { target, event_type.into(), callback, - &options.to_js(true), + &options.as_js(true), options.phase, ) } diff --git a/crates/file/src/blob.rs b/crates/file/src/blob.rs index 4bf116e4..f161c130 100644 --- a/crates/file/src/blob.rs +++ b/crates/file/src/blob.rs @@ -252,7 +252,7 @@ impl File { let blob = self.deref().slice(start, end); let raw_mime_type = self.raw_mime_type(); - let mime_type = if raw_mime_type == "" { + let mime_type = if raw_mime_type.is_empty() { None } else { Some(raw_mime_type) @@ -261,7 +261,7 @@ impl File { File::new_( &self.name(), blob.into(), - mime_type.as_ref().map(|s| s.as_str()), + mime_type.as_deref(), Some(self.last_modified_time()), ) } @@ -309,9 +309,7 @@ impl From for Blob { /// [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) fn safe_u64_to_f64(number: u64) -> f64 { // Max integer stably representable by f64 - // todo use js_sys::Number::MAX_SAFE_INTEGER once stable - const MAX_SAFE_INTEGER: u64 = 9007199254740991; // (2^53 - 1) - if number > MAX_SAFE_INTEGER { + if number > (js_sys::Number::MAX_SAFE_INTEGER as u64) { throw_str("a rust number was too large and could not be represented in JavaScript"); } number as f64 @@ -319,8 +317,7 @@ fn safe_u64_to_f64(number: u64) -> f64 { fn safe_u128_to_f64(number: u128) -> f64 { // Max integer stably representable by f64 - // todo use js_sys::Number::MAX_SAFE_INTEGER once stable - const MAX_SAFE_INTEGER: u128 = 9007199254740991; // (2^53 - 1) + const MAX_SAFE_INTEGER: u128 = js_sys::Number::MAX_SAFE_INTEGER as u128; // (2^53 - 1) if number > MAX_SAFE_INTEGER { throw_str("a rust number was too large and could not be represented in JavaScript"); } @@ -330,12 +327,11 @@ fn safe_u128_to_f64(number: u128) -> f64 { /// Like safe_u64_to_f64, but additionally checks that the number is an integer. fn safe_f64_to_u64(number: f64) -> u64 { // Max integer stably representable by f64 - // todo use js_sys::Number::MAX_SAFE_INTEGER once stable - const MAX_SAFE_INTEGER: f64 = 9007199254740991.0; // (2^53 - 1) - if number > MAX_SAFE_INTEGER { + if number > js_sys::Number::MAX_SAFE_INTEGER { throw_str("a rust number was too large and could not be represented in JavaScript"); } - if number.floor() != number { + + if number.fract() != 0.0 { throw_str( "a number could not be converted to an integer because it was not a whole number", ); diff --git a/crates/file/src/file_reader.rs b/crates/file/src/file_reader.rs index 01c03ad4..d1a8f1f6 100644 --- a/crates/file/src/file_reader.rs +++ b/crates/file/src/file_reader.rs @@ -228,10 +228,7 @@ enum ReadyState { impl ReadyState { fn is_done(&self) -> bool { - match self { - ReadyState::Done => true, - _ => false, - } + matches!(self, ReadyState::Done) } } diff --git a/src/lib.rs b/src/lib.rs index 33650a6b..bfeae3b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,9 @@ // Re-exports of toolkit crates. pub use gloo_console_timer as console_timer; +pub use gloo_dialogs as dialogs; pub use gloo_events as events; pub use gloo_file as file; +pub use gloo_render as render; pub use gloo_storage as storage; pub use gloo_timers as timers; -pub use gloo_dialogs as dialogs; -pub use gloo_render as render; \ No newline at end of file