Implement `Decode` for `Box<str>` (#562)

This commit is contained in:
Sabrina Jewson 2022-07-23 10:56:42 +01:00 committed by GitHub
parent 21561c3eb8
commit 035baf735f
1 changed files with 7 additions and 0 deletions

View File

@ -321,6 +321,13 @@ impl Decode for String {
}
impl_borrow_decode!(String);
impl Decode for Box<str> {
fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError> {
String::decode(decoder).map(String::into_boxed_str)
}
}
impl_borrow_decode!(Box<str>);
impl Encode for String {
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
self.as_bytes().encode(encoder)