Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bytes-str/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
35 changes: 35 additions & 0 deletions crates/bytes-str/src/byte_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,41 @@ impl BytesStr {
self.bytes
}

/// Converts the [BytesStr] into a [Vec<u8>].
///
/// # 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<u8> {
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
Expand Down
16 changes: 16 additions & 0 deletions crates/bytes-str/src/byte_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,22 @@ impl BytesString {
})
}

/// Converts the [BytesString] into a [Vec<u8>].
///
/// # 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<u8> {
self.bytes.into()
}

/// Converts a [BytesString] into a [String].
///
/// # Examples
Expand Down
Loading