From 4fe09940a72439332945b6fb09ec942a16500888 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 14 Oct 2021 13:39:53 +0200 Subject: [PATCH] make values Clone Signed-off-by: Wolfgang Bumiller --- perlmod/src/array.rs | 1 + perlmod/src/hash.rs | 1 + perlmod/src/scalar.rs | 7 +++++++ perlmod/src/value.rs | 1 + 4 files changed, 10 insertions(+) diff --git a/perlmod/src/array.rs b/perlmod/src/array.rs index 895fcdf..fe4f216 100644 --- a/perlmod/src/array.rs +++ b/perlmod/src/array.rs @@ -11,6 +11,7 @@ use crate::Value; /// An owned reference to a perl array value (AV). /// /// This keeps a reference to a value which lives in the perl interpreter. +#[derive(Clone)] #[repr(transparent)] pub struct Array(Scalar); diff --git a/perlmod/src/hash.rs b/perlmod/src/hash.rs index 64ebba8..19cfb78 100644 --- a/perlmod/src/hash.rs +++ b/perlmod/src/hash.rs @@ -10,6 +10,7 @@ use crate::Value; /// An owned reference to a perl hash value (HV). /// /// This keeps a reference to a value which lives in the perl interpreter. +#[derive(Clone)] #[repr(transparent)] pub struct Hash(Scalar); diff --git a/perlmod/src/scalar.rs b/perlmod/src/scalar.rs index 1fb2b5f..fcde7e1 100644 --- a/perlmod/src/scalar.rs +++ b/perlmod/src/scalar.rs @@ -117,6 +117,13 @@ impl Scalar { } } +impl Clone for Scalar { + #[inline] + fn clone(&self) -> Self { + unsafe { Self::from_raw_ref(self.sv()) } + } +} + impl Drop for Scalar { fn drop(&mut self) { unsafe { diff --git a/perlmod/src/value.rs b/perlmod/src/value.rs index 338ad1f..5f22799 100644 --- a/perlmod/src/value.rs +++ b/perlmod/src/value.rs @@ -12,6 +12,7 @@ use crate::{Array, Hash, Scalar}; /// A higher level value. This is basically an [`SV`] already cast to [`AV`](crate::ffi::AV) or /// [`HV`](crate::ffi::HV) for arrays and hashes. +#[derive(Clone)] pub enum Value { Scalar(Scalar), Reference(Scalar),