Skip to content

Instantly share code, notes, and snippets.

@dherman
Created July 10, 2018 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dherman/e726a6e3dc96bd7b14d4c55d17cca6c5 to your computer and use it in GitHub Desktop.
Save dherman/e726a6e3dc96bd7b14d4c55d17cca6c5 to your computer and use it in GitHub Desktop.
pub trait IntoJs<'a, V: Value> {
fn into_js<C: Context<'a>>(self, cx: &mut C) -> Handle<'a, V>;
}
impl<'a, V: Value> IntoJs<'a, V> for Handle<'a, V> {
fn into_js<C: Context<'a>>(self, _: &mut C) -> Handle<'a, V> {
self
}
}
impl<'a, 'b> IntoJs<'a, JsString> for &'b str {
fn into_js<C: Context<'a>>(self, cx: &mut C) -> Handle<'a, JsString> {
cx.string(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment