From 0e65638ef89f3fb683aba3fd124b90df0887217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 12 Jun 2025 13:28:12 -0700 Subject: [PATCH 1/3] API --- crates/bytes-str/src/byte_str.rs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/bytes-str/src/byte_str.rs b/crates/bytes-str/src/byte_str.rs index 231255b..fa220ac 100644 --- a/crates/bytes-str/src/byte_str.rs +++ b/crates/bytes-str/src/byte_str.rs @@ -284,6 +284,41 @@ impl BytesStr { self.bytes } + /// Converts the [BytesStr] into a [Vec]. + /// + /// # Examples + /// + /// ``` + /// use bytes_str::BytesStr; + /// + /// let s = BytesStr::from_static("hello"); + /// let vec = s.into_vec(); + /// + /// assert_eq!(vec, b"hello"); + /// ``` + pub fn into_vec(self) -> Vec { + self.into_bytes().to_vec() + } + + /// Converts the [BytesStr] into a [String]. + /// + /// # Examples + /// + /// ``` + /// use bytes_str::BytesStr; + /// + /// let s = BytesStr::from_static("hello"); + /// let string = s.into_string(); + /// + /// assert_eq!(string, "hello"); + /// ``` + pub fn into_string(self) -> String { + unsafe { + // Safety: BytesStr is backed by a valid UTF-8 string. + String::from_utf8_unchecked(self.into_vec()) + } + } + /// Returns the length of the [BytesStr]. /// /// # Examples From 5d446f40b345b8acce5aa390bca37b648c4de614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 12 Jun 2025 13:28:32 -0700 Subject: [PATCH 2/3] into_vec --- crates/bytes-str/src/byte_string.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/bytes-str/src/byte_string.rs b/crates/bytes-str/src/byte_string.rs index 202d459..6f6dcf3 100644 --- a/crates/bytes-str/src/byte_string.rs +++ b/crates/bytes-str/src/byte_string.rs @@ -367,6 +367,22 @@ impl BytesString { }) } + /// Converts the [BytesString] into a [Vec]. + /// + /// # Examples + /// + /// ``` + /// use bytes_str::BytesString; + /// + /// let s = BytesString::from("hello"); + /// let vec = s.into_vec(); + /// + /// assert_eq!(vec, b"hello"); + /// ``` + pub fn into_vec(self) -> Vec { + self.bytes.into() + } + /// Converts a [BytesString] into a [String]. /// /// # Examples From dabed8c7fd14fd1850d7986a374d3499abfb5d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 12 Jun 2025 13:28:39 -0700 Subject: [PATCH 3/3] bump --- Cargo.lock | 2 +- crates/bytes-str/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827f35a..bc966a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "bytes-str" -version = "0.2.6" +version = "0.2.7" dependencies = [ "bytes", "rkyv", diff --git a/crates/bytes-str/Cargo.toml b/crates/bytes-str/Cargo.toml index fdfe186..90e59f7 100644 --- a/crates/bytes-str/Cargo.toml +++ b/crates/bytes-str/Cargo.toml @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = { workspace = true } name = "bytes-str" repository = { workspace = true } -version = "0.2.6" +version = "0.2.7" [features] rkyv = ["dep:rkyv", "rkyv/bytes-1"]