Skip to content

Commit 5732303

Browse files
committed
feat: Add take_data() to all primitive object types.
That is the new, most direct way to obtain its data which otherwise is immovable.
1 parent 88f2e6c commit 5732303

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

gix/src/object/blob.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ impl Blob<'_> {
165165
pub fn detach(self) -> ObjectDetached {
166166
self.into()
167167
}
168+
169+
/// Retrieve this instance's data, leaving its own data empty.
170+
///
171+
/// This method works around the immovability of members of this type.
172+
pub fn take_data(&mut self) -> Vec<u8> {
173+
std::mem::take(&mut self.data)
174+
}
168175
}

gix/src/object/commit.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ impl<'repo> Commit<'repo> {
3535
pub fn detach(self) -> ObjectDetached {
3636
self.into()
3737
}
38+
39+
/// Retrieve this instance's encoded data, leaving its own data empty.
40+
///
41+
/// This method works around the immovability of members of this type.
42+
pub fn take_data(&mut self) -> Vec<u8> {
43+
std::mem::take(&mut self.data)
44+
}
3845
}
3946

4047
impl<'repo> Commit<'repo> {

gix/src/object/tag.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@ impl Tag<'_> {
4040
pub fn detach(self) -> ObjectDetached {
4141
self.into()
4242
}
43+
44+
/// Retrieve this instance's encoded data, leaving its own data empty.
45+
///
46+
/// This method works around the immovability of members of this type.
47+
pub fn take_data(&mut self) -> Vec<u8> {
48+
std::mem::take(&mut self.data)
49+
}
4350
}

gix/src/object/tree/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,11 @@ impl Tree<'_> {
266266
pub fn detach(self) -> ObjectDetached {
267267
self.into()
268268
}
269+
270+
/// Retrieve this instance's encoded data, leaving its own data empty.
271+
///
272+
/// This method works around the immovability of members of this type.
273+
pub fn take_data(&mut self) -> Vec<u8> {
274+
std::mem::take(&mut self.data)
275+
}
269276
}

0 commit comments

Comments
 (0)