Skip to content

Commit

Permalink
feat: impl<T> From<T> for JsValue where T: IntoWasmAbi (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantamis authored Apr 11, 2024
1 parent 5a10a97 commit 90fb74d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/expand/borrow.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<'a> From<Borrow<'a>> for JsValue {
#[inline]
fn from(value: Borrow<'a>) -> Self {
value.into_js().unwrap_throw().into()
}
}
impl<'a> FromWasmAbi for Borrow<'a>
where
Self: _serde::de::DeserializeOwned,
Expand Down
6 changes: 6 additions & 0 deletions tests/expand/generic_enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T, U> From<GenericEnum<T, U>> for JsValue {
#[inline]
fn from(value: GenericEnum<T, U>) -> Self {
value.into_js().unwrap_throw().into()
}
}
impl<T, U> FromWasmAbi for GenericEnum<T, U>
where
Self: _serde::de::DeserializeOwned,
Expand Down
12 changes: 12 additions & 0 deletions tests/expand/generic_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T> From<GenericStruct<T>> for JsValue {
#[inline]
fn from(value: GenericStruct<T>) -> Self {
value.into_js().unwrap_throw().into()
}
}
impl<T> FromWasmAbi for GenericStruct<T>
where
Self: _serde::de::DeserializeOwned,
Expand Down Expand Up @@ -459,6 +465,12 @@ const _: () = {
<JsType as OptionIntoWasmAbi>::none()
}
}
impl<T> From<GenericNewtype<T>> for JsValue {
#[inline]
fn from(value: GenericNewtype<T>) -> Self {
value.into_js().unwrap_throw().into()
}
}
impl<T> FromWasmAbi for GenericNewtype<T>
where
Self: _serde::de::DeserializeOwned,
Expand Down
7 changes: 7 additions & 0 deletions tsify-next-macros/src/wasm_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ fn expand_into_wasm_abi(cont: &Container) -> TokenStream {
<JsType as OptionIntoWasmAbi>::none()
}
}

impl #impl_generics From<#ident #ty_generics> for JsValue {
#[inline]
fn from(value: #ident #ty_generics) -> Self {
value.into_js().unwrap_throw().into()
}
}
}
}

Expand Down

0 comments on commit 90fb74d

Please sign in to comment.