From 774e34adf1e835d4a8cead2ec5efced4aef24329 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 9 Dec 2019 07:19:22 +0800 Subject: [PATCH] Deref String to Value --- src/string.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/string.rs b/src/string.rs index 47d32f3e..69d00f3a 100644 --- a/src/string.rs +++ b/src/string.rs @@ -1,6 +1,7 @@ use std::convert::TryInto; use std::default::Default; use std::mem::forget; +use std::ops::Deref; use std::slice; use crate::isolate::CxxIsolate; @@ -10,6 +11,7 @@ use crate::support::int; use crate::support::Opaque; use crate::HandleScope; use crate::Local; +use crate::Value; extern "C" { fn v8__String__NewFromUtf8( @@ -142,3 +144,10 @@ impl String { unsafe { std::string::String::from_raw_parts(data, length, capacity) } } } + +impl Deref for String { + type Target = Value; + fn deref(&self) -> &Self::Target { + unsafe { &*(self as *const _ as *const Value) } + } +}