Tweak the API of the Val type (#679)

* Tweak the API of the `Val` type

A few updates to the API of the `Val` type:

* Added a payload for `V128`.
* Replace existing accessor methods with `Option`-returning versions.
* Add `unwrap_xxx` family of methods to extract a value and panic.
* Remove `Into` conversions which panic, since panicking in `From` or
  `Into` isn't idiomatic in Rust
* Add documentation to all methods/values/enums/etc.
* Rename `Val::default` to `Val::null`

* Run rustfmt

* Review comments
This commit is contained in:
Alex Crichton
2019-12-06 16:19:37 -06:00
committed by GitHub
parent 2597468b30
commit 3d69e04659
7 changed files with 103 additions and 107 deletions

View File

@@ -1553,7 +1553,11 @@ unsafe fn into_funcref(val: Val) -> *mut wasm_ref_t {
if let Val::AnyRef(AnyRef::Null) = val {
return ptr::null_mut();
}
let r = Box::new(wasm_ref_t { r: val.into() });
let anyref = match val.anyref() {
Some(anyref) => anyref,
None => return ptr::null_mut(),
};
let r = Box::new(wasm_ref_t { r: anyref });
Box::into_raw(r)
}