diff --git a/bytestring/CHANGES.md b/bytestring/CHANGES.md index e5d8d41e..14f2cde2 100644 --- a/bytestring/CHANGES.md +++ b/bytestring/CHANGES.md @@ -2,6 +2,9 @@ ## Unreleased - 2022-xx-xx - Minimum supported Rust version (MSRV) is now 1.49. +- Implement `From>` and `Into`. [#458] + +[#458]: https://github.com/actix/actix-net/pull/458 ## 1.0.0 - 2020-12-31 diff --git a/bytestring/src/lib.rs b/bytestring/src/lib.rs index 95a21870..39a153d2 100644 --- a/bytestring/src/lib.rs +++ b/bytestring/src/lib.rs @@ -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> for ByteString { + #[inline] + fn from(value: Box) -> Self { + Self(Bytes::from(value.into_boxed_bytes())) + } +} + +impl From for String { + #[inline] + fn from(value: ByteString) -> Self { + value.to_string() + } +} + impl TryFrom<&[u8]> for ByteString { type Error = str::Utf8Error;