feat(napi): implement From<String> for Buffer (#2002)

This commit is contained in:
Louis 2024-03-17 14:43:01 +00:00 committed by GitHub
parent 50623ca26b
commit 693f0ac269
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -234,6 +234,12 @@ impl From<&[u8]> for Buffer {
} }
} }
impl From<String> for Buffer {
fn from(inner: String) -> Self {
Buffer::from(inner.into_bytes())
}
}
impl AsRef<[u8]> for Buffer { impl AsRef<[u8]> for Buffer {
fn as_ref(&self) -> &[u8] { fn as_ref(&self) -> &[u8] {
// SAFETY: the pointer is guaranteed to be non-null, and guaranteed to be valid if `len` is not 0. // SAFETY: the pointer is guaranteed to be non-null, and guaranteed to be valid if `len` is not 0.