1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 20:51:06 +01:00

feat: impls for Box and String conversions (#458)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Marcus Griep 2022-06-10 23:22:34 -04:00 committed by GitHub
parent 49a034259f
commit eb5fa30ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -2,6 +2,9 @@
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.49.
- Implement `From<Box<str>>` and `Into<String>`. [#458]
[#458]: https://github.com/actix/actix-net/pull/458
## 1.0.0 - 2020-12-31

View File

@ -6,7 +6,11 @@
extern crate alloc;
use alloc::{string::String, vec::Vec};
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
use core::{borrow, convert::TryFrom, fmt, hash, ops, str};
use bytes::Bytes;
@ -110,6 +114,20 @@ impl From<&str> for ByteString {
}
}
impl From<Box<str>> for ByteString {
#[inline]
fn from(value: Box<str>) -> Self {
Self(Bytes::from(value.into_boxed_bytes()))
}
}
impl From<ByteString> for String {
#[inline]
fn from(value: ByteString) -> Self {
value.to_string()
}
}
impl TryFrom<&[u8]> for ByteString {
type Error = str::Utf8Error;