Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cranelift/entity/src/packed_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down