shared_vec/impls/
convert.rs1use crate::{Counter, String, Vec};
2use alloc::borrow::Cow;
3use alloc::boxed::Box;
4
5impl<C: Counter<usize>> From<Box<str>> for String<C> {
6 #[inline]
8 fn from(s: Box<str>) -> Self {
9 Self::from_boxed_str(s)
10 }
11}
12impl<C: Counter<usize>> From<&str> for String<C> {
13 #[inline]
15 fn from(s: &str) -> Self {
16 Self::from_boxed_str(s.into())
17 }
18}
19impl<C: Counter<usize>> From<&mut str> for String<C> {
20 #[inline]
22 fn from(s: &mut str) -> Self {
23 Self::from_boxed_str(s.into())
24 }
25}
26impl<C1: Counter<usize>, C2: Counter<usize>> From<&String<C2>> for String<C1> {
27 #[inline]
29 fn from(s: &String<C2>) -> Self {
30 Self::from_boxed_str(s.as_str().into())
31 }
32}
33impl<C: Counter<usize>> From<&alloc::string::String> for String<C> {
34 #[inline]
36 fn from(s: &alloc::string::String) -> Self {
37 Self::from(s.as_str())
38 }
39}
40impl<C: Counter<usize>> From<alloc::string::String> for String<C> {
41 #[inline]
44 fn from(s: alloc::string::String) -> Self {
45 Self::from_boxed_str(s.into_boxed_str())
46 }
47}
48impl<C: Counter<usize>> From<&String<C>> for alloc::string::String {
49 #[inline]
51 fn from(s: &String<C>) -> Self {
52 alloc::string::String::from(s.as_str())
53 }
54}
55impl<C: Counter<usize>> From<String<C>> for alloc::string::String {
56 #[inline]
58 fn from(s: String<C>) -> Self {
59 alloc::string::String::from(s.as_str())
60 }
61}
62
63impl<C: Counter<usize>> From<Cow<'_, str>> for String<C> {
64 #[inline]
69 fn from(s: Cow<'_, str>) -> Self {
70 match s {
71 Cow::Borrowed(s) => Self::from_boxed_str(s.into()),
72 Cow::Owned(s) => Self::from_boxed_str(s.into_boxed_str()),
73 }
74 }
75}
76
77impl<C: Counter<usize>, T> From<Box<[T]>> for Vec<C, T> {
78 #[inline]
79 fn from(data: Box<[T]>) -> Self {
80 Self::from_boxed_slice(data)
81 }
82}