From 1a382d93ecd4ec56947a113fbfaebb06fb5baa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 9 Jun 2025 13:28:38 -0700 Subject: [PATCH 1/2] apis --- crates/bytes-str/src/byte_str.rs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/bytes-str/src/byte_str.rs b/crates/bytes-str/src/byte_str.rs index 6a6a6e2..231255b 100644 --- a/crates/bytes-str/src/byte_str.rs +++ b/crates/bytes-str/src/byte_str.rs @@ -185,6 +185,40 @@ impl BytesStr { } } + /// Creates a new BytesStr from a [str]. + /// + /// # Examples + /// + /// ``` + /// use bytes_str::BytesStr; + /// + /// let s = BytesStr::from_str_slice("hello"); + /// + /// assert_eq!(s.as_str(), "hello"); + /// ``` + pub fn from_str_slice(bytes: &str) -> Self { + Self { + bytes: Bytes::copy_from_slice(bytes.as_bytes()), + } + } + + /// Creates a new BytesStr from a [String]. + /// + /// # Examples + /// + /// ``` + /// use bytes_str::BytesStr; + /// + /// let s = BytesStr::from_string("hello".to_string()); + /// + /// assert_eq!(s.as_str(), "hello"); + /// ``` + pub fn from_string(bytes: String) -> Self { + Self { + bytes: Bytes::from(bytes), + } + } + /// Creates a new BytesStr from a static UTF-8 slice. /// /// # Examples From eb66272801a99a2df5359e53b33a13e73244e0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 9 Jun 2025 13:28:45 -0700 Subject: [PATCH 2/2] 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 67a6940..ef9a54c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "bytes-str" -version = "0.2.4" +version = "0.2.5" dependencies = [ "bytes", "rkyv", diff --git a/crates/bytes-str/Cargo.toml b/crates/bytes-str/Cargo.toml index 388ff42..85548d0 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.4" +version = "0.2.5" [features] rkyv = ["dep:rkyv", "rkyv/bytes-1"]