Skip to content

Commit

Permalink
Implement From<NonNull<T>> for JsValue (#3877)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Mar 9, 2024
1 parent e22f754 commit ad4e443
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

## Unreleased

### Added

* Implement `From<NonNull<T>>` for `JsValue`.
[#3877](https://github.com/rustwasm/wasm-bindgen/pull/3877)

### Fixed

* Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`.
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use core::mem;
use core::ops::{
Add, BitAnd, BitOr, BitXor, Deref, DerefMut, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub,
};
use core::ptr::NonNull;
use core::u32;

use crate::convert::{FromWasmAbi, TryFromJsValue, WasmRet, WasmSlice};
Expand Down Expand Up @@ -790,6 +791,13 @@ impl<T> From<*const T> for JsValue {
}
}

impl<T> From<NonNull<T>> for JsValue {
#[inline]
fn from(s: NonNull<T>) -> JsValue {
JsValue::from(s.as_ptr() as usize)
}
}

if_std! {
impl<'a> From<&'a String> for JsValue {
#[inline]
Expand Down

0 comments on commit ad4e443

Please sign in to comment.