From 94885bc2932fa0e40feee877f7f68fc5e68f76c8 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sat, 2 Apr 2022 14:37:11 +0200 Subject: experiment(serde_v8): derive_more enabled opaque wrappers (#14096) --- ext/web/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ext/web/lib.rs') diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 21fa285ba..423e53c51 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -129,8 +129,7 @@ fn op_base64_decode(input: String) -> Result { } #[op] -fn op_base64_atob(s: ByteString) -> Result { - let mut s = s.0; +fn op_base64_atob(mut s: ByteString) -> Result { s.retain(|c| !c.is_ascii_whitespace()); // If padding is expected, fail if not 4-byte aligned @@ -140,7 +139,7 @@ fn op_base64_atob(s: ByteString) -> Result { ); } - Ok(ByteString(b64_decode(&s)?)) + Ok(b64_decode(&s)?.into()) } fn b64_decode(input: &[u8]) -> Result, AnyError> { @@ -185,7 +184,7 @@ fn op_base64_encode(s: ZeroCopyBuf) -> Result { #[op] fn op_base64_btoa(s: ByteString) -> Result { - Ok(b64_encode(&s)) + Ok(b64_encode(s)) } fn b64_encode(s: impl AsRef<[u8]>) -> String { @@ -270,7 +269,7 @@ fn op_encoding_decode( .max_utf16_buffer_length(data.len()) .ok_or_else(|| range_error("Value too large to decode."))?; - let mut output = U16String::with_zeroes(max_buffer_length); + let mut output = vec![0; max_buffer_length]; if fatal { let (result, _, written) = @@ -278,7 +277,7 @@ fn op_encoding_decode( match result { DecoderResult::InputEmpty => { output.truncate(written); - Ok(output) + Ok(output.into()) } DecoderResult::OutputFull => { Err(range_error("Provided buffer too small.")) @@ -293,7 +292,7 @@ fn op_encoding_decode( match result { CoderResult::InputEmpty => { output.truncate(written); - Ok(output) + Ok(output.into()) } CoderResult::OutputFull => Err(range_error("Provided buffer too small.")), } -- cgit v1.2.3