Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Implement `TryClone` for `PackedOption` (#12617)

Nick Fitzgerald8fd787ee22c6
diff --git a/cranelift/entity/src/packed_option.rs b/cranelift/entity/src/packed_option.rs
index 36f97d6d4d..fd1451802a 100644
--- a/cranelift/entity/src/packed_option.rs
+++ b/cranelift/entity/src/packed_option.rs
@@ -7,8 +7,8 @@
//! This module provides a `PackedOption<T>` 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: ReservedValue>(T);
+impl<T> TryClone for PackedOption<T>
+where
+ T: ReservedValue + TryClone,
+{
+ fn try_clone(&self) -> Result<Self, OutOfMemory> {
+ Ok(Self(self.0.try_clone()?))
+ }
+}
+
impl<T: ReservedValue> PackedOption<T> {
/// Returns `true` if the packed option is a `None` value.
pub fn is_none(&self) -> bool {