Skip to content

Commit

Permalink
Fix formatting and lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Sep 30, 2023
1 parent 1725195 commit 7c6d4b7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/readable/byob_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ impl<'stream> ReadableStreamBYOBReader<'stream> {
return Err(js_sys::Error::new("Already locked"));
}
Ok(Self {
raw: stream.as_raw().get_reader_with_options(
&sys::ReadableStreamGetReaderOptions::new()
.mode(sys::ReadableStreamReaderMode::Byob),
).unchecked_into(),
raw: stream
.as_raw()
.get_reader_with_options(
sys::ReadableStreamGetReaderOptions::new()
.mode(sys::ReadableStreamReaderMode::Byob),
)
.unchecked_into(),
_stream: PhantomData,
})
}
Expand Down Expand Up @@ -175,7 +178,8 @@ impl<'stream> ReadableStreamBYOBReader<'stream> {
/// return an error and leave the reader locked to the stream.
#[inline]
pub fn try_release_lock(self) -> Result<(), (js_sys::Error, Self)> {
Ok(self.as_raw().release_lock())
self.as_raw().release_lock();
Ok(())
}

/// Converts this `ReadableStreamBYOBReader` into an [`AsyncRead`].
Expand Down
7 changes: 4 additions & 3 deletions src/readable/default_reader.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::marker::PhantomData;

use wasm_bindgen::JsValue;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;

use crate::util::promise_to_void_future;

use super::{IntoStream, ReadableStream, sys};
use super::{sys, IntoStream, ReadableStream};

/// A [`ReadableStreamDefaultReader`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader)
/// that can be used to read chunks from a [`ReadableStream`](ReadableStream).
Expand Down Expand Up @@ -111,7 +111,8 @@ impl<'stream> ReadableStreamDefaultReader<'stream> {
/// return an error and leave the reader locked to the stream.
#[inline]
pub fn try_release_lock(self) -> Result<(), (js_sys::Error, Self)> {
Ok(self.as_raw().release_lock())
self.as_raw().release_lock();
Ok(())
}

/// Converts this `ReadableStreamDefaultReader` into a [`Stream`].
Expand Down
13 changes: 6 additions & 7 deletions src/readable/into_async_read.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use core::pin::Pin;
use core::task::{Context, Poll};

use futures_util::FutureExt;
use futures_util::io::{AsyncRead, Error};
use futures_util::ready;
use futures_util::FutureExt;
use js_sys::{Object, Uint8Array};
use wasm_bindgen::JsCast;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;

use crate::util::{checked_cast_to_usize, clamp_to_u32, js_to_io_error};

use super::ReadableStreamBYOBReader;
use super::sys::ReadableStreamBYOBReadResult;
use super::ReadableStreamBYOBReader;

/// An [`AsyncRead`] for the [`into_async_read`](super::ReadableStream::into_async_read) method.
///
Expand Down Expand Up @@ -84,13 +84,12 @@ impl<'reader> AsyncRead for IntoAsyncRead<'reader> {
_ => Uint8Array::new_with_length(buf_len),
};
// Limit to output buffer size
let buffer = buffer
.subarray(0, buf_len)
.unchecked_into::<Object>();
let buffer = buffer.subarray(0, buf_len).unchecked_into::<Object>();
match &self.reader {
Some(reader) => {
// Read into internal buffer and store its future
let fut = JsFuture::from(reader.as_raw().read_with_array_buffer_view(&buffer));
let fut =
JsFuture::from(reader.as_raw().read_with_array_buffer_view(&buffer));
self.fut.insert(fut)
}
None => {
Expand Down
5 changes: 1 addition & 4 deletions src/readable/into_underlying_byte_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ impl Inner {
// We set autoAllocateChunkSize, so there should always be a BYOB request.
let request = controller.byob_request().unwrap_throw();
// Resize the buffer to fit the BYOB request.
let request_view = request
.view()
.unwrap_throw()
.unchecked_into::<Uint8Array>();
let request_view = request.view().unwrap_throw().unchecked_into::<Uint8Array>();
let request_len = clamp_to_usize(request_view.byte_length());
if self.buffer.len() < request_len {
self.buffer.resize(request_len, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/readable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ReadableStream {
&source.into_raw(),
&strategy.into_raw().unchecked_into(),
)
.unwrap_or_else(|error| throw_val(error.into()));
.unwrap_or_else(|error| throw_val(error));
Self { raw }
}

Expand Down
8 changes: 5 additions & 3 deletions src/writable/default_writer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::marker::PhantomData;

use wasm_bindgen::{JsValue, throw_val};
use wasm_bindgen::{throw_val, JsValue};

use crate::util::promise_to_void_future;

use super::{IntoAsyncWrite, IntoSink, sys, WritableStream};
use super::{sys, IntoAsyncWrite, IntoSink, WritableStream};

/// A [`WritableStreamDefaultWriter`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter)
/// that can be used to write chunks to a [`WritableStream`](WritableStream).
Expand Down Expand Up @@ -50,7 +50,9 @@ impl<'stream> WritableStreamDefaultWriter<'stream> {
/// * It will return zero if the stream is closed.
#[inline]
pub fn desired_size(&self) -> Option<f64> {
self.as_raw().desired_size().unwrap_or_else(|error| throw_val(error.into()))
self.as_raw()
.desired_size()
.unwrap_or_else(|error| throw_val(error))
}

/// Waits until the desired size to fill the stream's internal queue transitions
Expand Down
2 changes: 1 addition & 1 deletion src/writable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl WritableStream {
// Use the default queuing strategy (with a HWM of 1 chunk).
// We shouldn't set HWM to 0, since that would break piping to the writable stream.
let raw = sys::WritableStream::new_with_underlying_sink(&sink.into_raw().unchecked_into())
.unwrap_or_else(|error| throw_val(error.into()));
.unwrap_or_else(|error| throw_val(error));
WritableStream { raw }
}

Expand Down

0 comments on commit 7c6d4b7

Please sign in to comment.