From 284a4db8907c77e355b32b043798cf9ccdf636d2 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 18 Feb 2026 12:06:58 -0800 Subject: [PATCH] Implement `TryClone` for `PackedOption` --- cranelift/entity/src/packed_option.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cranelift/entity/src/packed_option.rs b/cranelift/entity/src/packed_option.rs index 36f97d6d4da2..fd1451802a8f 100644 --- a/cranelift/entity/src/packed_option.rs +++ b/cranelift/entity/src/packed_option.rs @@ -7,8 +7,8 @@ //! This module provides a `PackedOption` for types that have a reserved value that can be used //! to represent `None`. -use core::fmt; -use core::mem; +use core::{fmt, mem}; +use wasmtime_core::{alloc::TryClone, error::OutOfMemory}; #[cfg(feature = "enable-serde")] use serde_derive::{Deserialize, Serialize}; @@ -30,6 +30,15 @@ pub trait ReservedValue { #[repr(transparent)] pub struct PackedOption(T); +impl TryClone for PackedOption +where + T: ReservedValue + TryClone, +{ + fn try_clone(&self) -> Result { + Ok(Self(self.0.try_clone()?)) + } +} + impl PackedOption { /// Returns `true` if the packed option is a `None` value. pub fn is_none(&self) -> bool {