|
1 | 1 | //! Working with GC `eqref`s. |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | | - AnyRef, ArrayRef, ArrayType, AsContext, GcRefImpl, GcRootIndex, HeapType, I31, OwnedRooted, |
5 | | - RefType, Rooted, StructRef, StructType, ValRaw, ValType, WasmTy, |
| 4 | + AnyRef, ArrayRef, ArrayType, AsContext, AsContextMut, GcRefImpl, GcRootIndex, HeapType, I31, |
| 5 | + OwnedRooted, RefType, Rooted, StructRef, StructType, ValRaw, ValType, WasmTy, |
6 | 6 | prelude::*, |
7 | 7 | runtime::vm::VMGcRef, |
8 | 8 | store::{AutoAssertNoGc, StoreOpaque}, |
@@ -248,6 +248,33 @@ impl EqRef { |
248 | 248 | } |
249 | 249 | } |
250 | 250 |
|
| 251 | + /// Construct an `eqref` from an `i31`. |
| 252 | + /// |
| 253 | + /// # Example |
| 254 | + /// |
| 255 | + /// ``` |
| 256 | + /// # use wasmtime::*; |
| 257 | + /// # fn _foo() -> Result<()> { |
| 258 | + /// let mut store = Store::<()>::default(); |
| 259 | + /// |
| 260 | + /// // Create an `i31`. |
| 261 | + /// let i31 = I31::wrapping_u32(999); |
| 262 | + /// |
| 263 | + /// // Convert it into an `eqref`. |
| 264 | + /// let eqref = EqRef::from_i31(&mut store, i31); |
| 265 | + /// # Ok(()) |
| 266 | + /// # } |
| 267 | + /// ``` |
| 268 | + pub fn from_i31(mut store: impl AsContextMut, value: I31) -> Rooted<Self> { |
| 269 | + let mut store = AutoAssertNoGc::new(store.as_context_mut().0); |
| 270 | + Self::_from_i31(&mut store, value) |
| 271 | + } |
| 272 | + |
| 273 | + pub(crate) fn _from_i31(store: &mut AutoAssertNoGc<'_>, value: I31) -> Rooted<Self> { |
| 274 | + let gc_ref = VMGcRef::from_i31(value.runtime_i31()); |
| 275 | + Rooted::new(store, gc_ref) |
| 276 | + } |
| 277 | + |
251 | 278 | /// Is this `eqref` an `i31`? |
252 | 279 | /// |
253 | 280 | /// # Errors |
|
0 commit comments