Skip to content

Commit

Permalink
feat: TreeRef::to_owned() and Tree::into_owned() for a convenient…
Browse files Browse the repository at this point in the history
… way to get a fully-owned `Tree`
  • Loading branch information
Byron committed Sep 5, 2024
1 parent 39d8e03 commit 7c48556
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion gix-object/src/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
bstr::{BStr, BString},
tree, Tree,
tree, Tree, TreeRef,
};
use std::cmp::Ordering;

Expand Down Expand Up @@ -194,6 +194,21 @@ impl EntryMode {
}
}

impl TreeRef<'_> {
/// Convert this instance into its own version, creating a copy of all data.
///
/// This will temporarily allocate an extra copy in memory, so at worst three copies of the tree exist
/// at some intermediate point in time. Use [`Self::into_owned()`] to avoid this.
pub fn to_owned(&self) -> Tree {
self.clone().into()
}

/// Convert this instance into its own version, creating a copy of all data.
pub fn into_owned(self) -> Tree {
self.into()
}
}

/// An element of a [`TreeRef`][crate::TreeRef::entries].
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down

0 comments on commit 7c48556

Please sign in to comment.