bencode_minimal/
into_str.rs1use super::Str;
2use std::borrow::Cow;
3
4pub trait IntoStr<'a> {
6 fn into_str(self) -> Str<'a>;
7}
8
9impl<'a, 'b: 'a> IntoStr<'a> for &'b [u8] {
10 fn into_str(self) -> Str<'a> {
11 Cow::Borrowed(self)
12 }
13}
14
15impl<'a, 'b: 'a, const N: usize> IntoStr<'a> for &'b [u8; N] {
16 fn into_str(self) -> Str<'a> {
17 Cow::Borrowed(self)
18 }
19}
20
21impl<'a, 'b: 'a> IntoStr<'a> for &'b str {
22 fn into_str(self) -> Str<'a> {
23 Cow::Borrowed(self.as_ref())
24 }
25}
26
27impl<'a> IntoStr<'a> for Vec<u8> {
28 fn into_str(self) -> Str<'a> {
29 Cow::Owned(self)
30 }
31}
32
33impl<'a, const N: usize> IntoStr<'a> for [u8; N] {
34 fn into_str(self) -> Str<'a> {
35 Cow::Owned(self.to_vec())
36 }
37}
38
39impl<'a> IntoStr<'a> for String {
40 fn into_str(self) -> Str<'a> {
41 Cow::Owned(self.into_bytes())
42 }
43}