Skip to content

Commit

Permalink
Merge pull request #1119 from zeenix/value-clone
Browse files Browse the repository at this point in the history
🏷️ zv: Implement Clone for *Value
  • Loading branch information
zeenix authored Nov 2, 2024
2 parents 7ab9aa9 + bcfe9ed commit e08700a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions zvariant/src/owned_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ impl<'de> Deserialize<'de> for OwnedValue {
}
}

impl Clone for OwnedValue {
/// Clone the value.
///
/// # Panics
///
/// This method can only fail on Unix platforms for [`Value::Fd`] variant containing an
/// [`Fd::Owned`] variant. This happens when the current process exceeds the limit on maximum
/// number of open file descriptors.
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

#[cfg(test)]
mod tests {
use std::{collections::HashMap, error::Error};
Expand Down
14 changes: 14 additions & 0 deletions zvariant/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,20 @@ impl<'a> TryFrom<&Value<'a>> for Value<'a> {
}
}

impl Clone for Value<'_> {
/// Clone the value.
///
/// # Panics
///
/// This method can only fail on Unix platforms for [`Value::Fd`] variant containing an
/// [`Fd::Owned`] variant. This happens when the current process exceeds the limit on maximum
/// number of open file descriptors.
fn clone(&self) -> Self {
self.try_clone()
.expect("Process exceeded limit on maximum number of open file descriptors")
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down

0 comments on commit e08700a

Please sign in to comment.