1use crate::MetaString;
2
3pub trait CheapMetaString {
10 fn try_cheap_clone(&self) -> Option<MetaString>;
14}
15
16impl CheapMetaString for MetaString {
17 fn try_cheap_clone(&self) -> Option<MetaString> {
18 if self.is_cheaply_cloneable() {
19 Some(self.clone())
20 } else {
21 None
22 }
23 }
24}
25
26impl CheapMetaString for &str {
27 fn try_cheap_clone(&self) -> Option<MetaString> {
28 MetaString::try_inline(self)
29 }
30}
31
32impl CheapMetaString for String {
33 fn try_cheap_clone(&self) -> Option<MetaString> {
34 MetaString::try_inline(self)
35 }
36}
37
38impl<T> CheapMetaString for &T
39where
40 T: CheapMetaString,
41{
42 fn try_cheap_clone(&self) -> Option<MetaString> {
43 (*self).try_cheap_clone()
44 }
45}