From 4f7746da60e75ca5152026f91dcf920061bee6f4 Mon Sep 17 00:00:00 2001 From: Noa Date: Thu, 23 Feb 2023 09:32:35 -0600 Subject: [PATCH] Have StoreContext::data return &'a T (#5855) --- crates/wasmtime/src/store.rs | 2 +- crates/wasmtime/src/store/context.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/wasmtime/src/store.rs b/crates/wasmtime/src/store.rs index b78ca3beec..866aa39f15 100644 --- a/crates/wasmtime/src/store.rs +++ b/crates/wasmtime/src/store.rs @@ -980,7 +980,7 @@ impl<'a, T> StoreContext<'a, T> { /// Access the underlying data owned by this `Store`. /// /// Same as [`Store::data`]. - pub fn data(&self) -> &T { + pub fn data(&self) -> &'a T { self.0.data() } diff --git a/crates/wasmtime/src/store/context.rs b/crates/wasmtime/src/store/context.rs index f50557f9dc..4e15eaabf7 100644 --- a/crates/wasmtime/src/store/context.rs +++ b/crates/wasmtime/src/store/context.rs @@ -161,6 +161,13 @@ impl AsContextMut for StoreContextMut<'_, T> { } } +impl<'a, T> From> for StoreContext<'a, T> { + #[inline] + fn from(store: StoreContextMut<'a, T>) -> StoreContext<'a, T> { + StoreContext(store.0) + } +} + // Implementations for internal consumers, but these aren't public types so // they're not publicly accessible for crate consumers. impl AsContext for &'_ StoreInner {