Skip to content

Commit

Permalink
feat: Add take_data() to all primitive object types.
Browse files Browse the repository at this point in the history
That is the new, most direct way to obtain its data which otherwise
is immovable.
  • Loading branch information
Byron committed Oct 12, 2023
1 parent 88f2e6c commit 5732303
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gix/src/object/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,11 @@ impl Blob<'_> {
pub fn detach(self) -> ObjectDetached {
self.into()
}

/// Retrieve this instance's data, leaving its own data empty.
///
/// This method works around the immovability of members of this type.
pub fn take_data(&mut self) -> Vec<u8> {
std::mem::take(&mut self.data)
}
}
7 changes: 7 additions & 0 deletions gix/src/object/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ impl<'repo> Commit<'repo> {
pub fn detach(self) -> ObjectDetached {
self.into()
}

/// Retrieve this instance's encoded data, leaving its own data empty.
///
/// This method works around the immovability of members of this type.
pub fn take_data(&mut self) -> Vec<u8> {
std::mem::take(&mut self.data)
}
}

impl<'repo> Commit<'repo> {
Expand Down
7 changes: 7 additions & 0 deletions gix/src/object/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ impl Tag<'_> {
pub fn detach(self) -> ObjectDetached {
self.into()
}

/// Retrieve this instance's encoded data, leaving its own data empty.
///
/// This method works around the immovability of members of this type.
pub fn take_data(&mut self) -> Vec<u8> {
std::mem::take(&mut self.data)
}
}
7 changes: 7 additions & 0 deletions gix/src/object/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,11 @@ impl Tree<'_> {
pub fn detach(self) -> ObjectDetached {
self.into()
}

/// Retrieve this instance's encoded data, leaving its own data empty.
///
/// This method works around the immovability of members of this type.
pub fn take_data(&mut self) -> Vec<u8> {
std::mem::take(&mut self.data)
}
}

0 comments on commit 5732303

Please sign in to comment.