From 2d98857f0cbc9d60bc161346d18ddddcd292f251 Mon Sep 17 00:00:00 2001 From: hanxuanliang Date: Sat, 11 May 2024 13:03:27 +0800 Subject: [PATCH 1/2] feat(core/types): add new buffer util fns --- core/src/types/buffer.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/core/src/types/buffer.rs b/core/src/types/buffer.rs index a89cc24a0de..ef6802503f7 100644 --- a/core/src/types/buffer.rs +++ b/core/src/types/buffer.rs @@ -317,6 +317,47 @@ impl Buffer { } } } + + /// Splits the current object into two parts at the specified index (`at`). + /// + /// The portion before the index is stored in the left tuple element, while the portion + /// after the index is stored in the right tuple element. + #[inline] + pub fn split(&self, at: usize) -> (Self, Self) { + let mut left = self.clone(); + let mut right = self.clone(); + + left.truncate(at); + right.advance(at); + + (left, right) + } + + /// 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 { + 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> for Buffer { From 43576f5323aad2d3c7f153ccfb2e4f6bef220e00 Mon Sep 17 00:00:00 2001 From: hanxuanliang Date: Sun, 12 May 2024 08:45:39 +0800 Subject: [PATCH 2/2] feat(core/types): remove split fn --- core/src/types/buffer.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/core/src/types/buffer.rs b/core/src/types/buffer.rs index ef6802503f7..cbbfc9a7efc 100644 --- a/core/src/types/buffer.rs +++ b/core/src/types/buffer.rs @@ -318,21 +318,6 @@ impl Buffer { } } - /// Splits the current object into two parts at the specified index (`at`). - /// - /// The portion before the index is stored in the left tuple element, while the portion - /// after the index is stored in the right tuple element. - #[inline] - pub fn split(&self, at: usize) -> (Self, Self) { - let mut left = self.clone(); - let mut right = self.clone(); - - left.truncate(at); - right.advance(at); - - (left, right) - } - /// 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