Skip to content

Commit

Permalink
Rustfmt and clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Nov 22, 2022
1 parent 8739b40 commit 4a6c6f8
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions boa_engine/src/object/builtins/jsarraybuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl JsArrayBuffer {
/// let array_buffer = JsArrayBuffer::new(4, context).unwrap();
///
/// assert_eq!(array_buffer.take().unwrap(), vec![0_u8; 4]);
///
///
/// ```
#[inline]
pub fn new(byte_length: usize, context: &mut Context) -> JsResult<Self> {
Expand Down Expand Up @@ -60,16 +60,16 @@ impl JsArrayBuffer {
/// # object::builtins::JsArrayBuffer,
/// # Context,
/// # };
///
///
/// # // Initialize context
/// # let context = &mut Context::default();
///
///
/// // Create a buffer from a chunk of data
/// let data_block: Vec<u8> = (0..5).collect();
/// let array_buffer = JsArrayBuffer::from_byte_block(data_block, context).unwrap();
///
/// assert_eq!(array_buffer.take().unwrap(), (0..5).collect::<Vec<u8>>());
///
///
/// assert_eq!(array_buffer.take().unwrap(), (0..5).collect::<Vec<u8>>());
///
/// ```
#[inline]
pub fn from_byte_block(byte_block: Vec<u8>, context: &mut Context) -> JsResult<Self> {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl JsArrayBuffer {
}

/// Returns the byte length of the array buffer.
///
///
/// ```
/// # use boa_engine::{
/// # object::builtins::JsArrayBuffer,
Expand All @@ -137,7 +137,7 @@ impl JsArrayBuffer {
///
/// // Take the inner buffer
/// let buffer_length = array_buffer.byte_length(context);
///
///
/// assert_eq!(buffer_length, 5_usize);
/// ```
#[inline]
Expand All @@ -149,9 +149,9 @@ impl JsArrayBuffer {
}

/// Take the inner `ArrayBuffer`'s `array_buffer_data` field and replace it with `None`
///
/// Note: This causes the pre-existing JsArrayBuffer to become detached.
///
///
/// Note: This causes the pre-existing `JsArrayBuffer` to become detached.
///
/// ```
/// # use boa_engine::{
/// # object::builtins::JsArrayBuffer,
Expand All @@ -165,13 +165,13 @@ impl JsArrayBuffer {
///
/// // Take the inner buffer
/// let internal_buffer = array_buffer.take().unwrap();
///
///
/// assert_eq!(internal_buffer, (0..5).collect::<Vec<u8>>());
///
///
/// // Anymore interaction with the buffer will return an error
/// let detached_err = array_buffer.take();
/// assert!(detached_err.is_err());
///
///
/// ```
#[inline]
pub fn take(&self) -> JsResult<Vec<u8>> {
Expand All @@ -181,7 +181,11 @@ impl JsArrayBuffer {
.expect("inner must be an ArrayBuffer")
.array_buffer_data
.take()
.ok_or(JsNativeError::typ().with_message("ArrayBuffer is detached").into())
.ok_or_else(|| {
JsNativeError::typ()
.with_message("ArrayBuffer is detached")
.into()
})
}
}

Expand Down

0 comments on commit 4a6c6f8

Please sign in to comment.