make values Clone

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-10-14 13:39:53 +02:00
parent 814014b874
commit 4fe09940a7
4 changed files with 10 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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),