From 693f0ac2697c26f14bb4094caf5de1cd347a547f Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 17 Mar 2024 14:43:01 +0000 Subject: [PATCH] feat(napi): implement From for Buffer (#2002) --- crates/napi/src/bindgen_runtime/js_values/buffer.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/napi/src/bindgen_runtime/js_values/buffer.rs b/crates/napi/src/bindgen_runtime/js_values/buffer.rs index d5857ec6..2cc6bdf3 100644 --- a/crates/napi/src/bindgen_runtime/js_values/buffer.rs +++ b/crates/napi/src/bindgen_runtime/js_values/buffer.rs @@ -234,6 +234,12 @@ impl From<&[u8]> for Buffer { } } +impl From for Buffer { + fn from(inner: String) -> Self { + Buffer::from(inner.into_bytes()) + } +} + impl AsRef<[u8]> for Buffer { fn as_ref(&self) -> &[u8] { // SAFETY: the pointer is guaranteed to be non-null, and guaranteed to be valid if `len` is not 0.