mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 00:01:11 +01:00
feat: impls for Box and String conversions (#458)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
49a034259f
commit
eb5fa30ada
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user