Skip to content

Commit eb5fa30

Browse files
feat: impls for Box and String conversions (#458)
Co-authored-by: Rob Ede <[email protected]>
1 parent 49a0342 commit eb5fa30

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

bytestring/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased - 2022-xx-xx
44
- Minimum supported Rust version (MSRV) is now 1.49.
5+
- Implement `From<Box<str>>` and `Into<String>`. [#458]
6+
7+
[#458]: https://github.com/actix/actix-net/pull/458
58

69

710
## 1.0.0 - 2020-12-31

bytestring/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
extern crate alloc;
88

9-
use alloc::{string::String, vec::Vec};
9+
use alloc::{
10+
boxed::Box,
11+
string::{String, ToString},
12+
vec::Vec,
13+
};
1014
use core::{borrow, convert::TryFrom, fmt, hash, ops, str};
1115

1216
use bytes::Bytes;
@@ -110,6 +114,20 @@ impl From<&str> for ByteString {
110114
}
111115
}
112116

117+
impl From<Box<str>> for ByteString {
118+
#[inline]
119+
fn from(value: Box<str>) -> Self {
120+
Self(Bytes::from(value.into_boxed_bytes()))
121+
}
122+
}
123+
124+
impl From<ByteString> for String {
125+
#[inline]
126+
fn from(value: ByteString) -> Self {
127+
value.to_string()
128+
}
129+
}
130+
113131
impl TryFrom<&[u8]> for ByteString {
114132
type Error = str::Utf8Error;
115133

0 commit comments

Comments
 (0)