diff --git a/gix-object/src/tree/mod.rs b/gix-object/src/tree/mod.rs index 979940012e2..1d3c0838df0 100644 --- a/gix-object/src/tree/mod.rs +++ b/gix-object/src/tree/mod.rs @@ -1,6 +1,6 @@ use crate::{ bstr::{BStr, BString}, - tree, Tree, + tree, Tree, TreeRef, }; use std::cmp::Ordering; @@ -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))]