Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/types): add new buffer util fns #4598

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions core/src/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,32 @@ impl Buffer {
}
}
}

/// Splits the current object into two parts at the specified index (`at`).
///
/// The portion before the index is stored in the `left` object, while the portion
/// after the index is removed from the current object (`self`).
#[inline]
pub fn split_to(&mut self, at: usize) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, would you like to add test cases for them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly cc @hanxuanliang for a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that the issue has been delayed recently due to personal matters. I will finish the following pr content at the weekend

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that the issue has been delayed recently due to personal matters. I will finish the following pr content at the weekend

There's no hurry; I just want an update on the current status. You can return at any time.

let mut left = self.clone();

left.truncate(at);
self.advance(at);
left
}

/// Splits the current object into two parts at the specified index (`at`).
///
/// The portion before the index remains in the original object, while the portion
/// after the index is returned as a new object.
#[inline]
pub fn split_off(&mut self, at: usize) -> Self {
let mut right = self.clone();

self.truncate(at);
right.advance(at);
right
}
}

impl From<Vec<u8>> for Buffer {
Expand Down
Loading