Skip to content

Commit ffa782b

Browse files
committed
feat: TreeRef::to_owned() and Tree::into_owned() for a convenient way to get a fully-owned Tree
1 parent ab22cb7 commit ffa782b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

gix-object/src/tree/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
bstr::{BStr, BString},
3-
tree, Tree,
3+
tree, Tree, TreeRef,
44
};
55
use std::cmp::Ordering;
66

@@ -194,6 +194,21 @@ impl EntryMode {
194194
}
195195
}
196196

197+
impl TreeRef<'_> {
198+
/// Convert this instance into its own version, creating a copy of all data.
199+
///
200+
/// This will temporarily allocate an extra copy in memory, so at worst three copies of the tree exist
201+
/// at some intermediate point in time. Use [`Self::into_owned()`] to avoid this.
202+
pub fn to_owned(&self) -> Tree {
203+
self.clone().into()
204+
}
205+
206+
/// Convert this instance into its own version, creating a copy of all data.
207+
pub fn into_owned(self) -> Tree {
208+
self.into()
209+
}
210+
}
211+
197212
/// An element of a [`TreeRef`][crate::TreeRef::entries].
198213
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
199214
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

0 commit comments

Comments
 (0)