1use std::{
2 borrow::Cow,
3 mem::{forget, ManuallyDrop},
4};
5
6use crate::{
7 dynamic::{global_atom, global_wtf8_atom},
8 wtf8::{Wtf8, Wtf8Buf},
9 Atom, Wtf8Atom,
10};
11
12macro_rules! direct_from_impl {
13 ($T:ty) => {
14 impl From<$T> for Atom {
15 fn from(s: $T) -> Self {
16 global_atom(&s)
17 }
18 }
19 };
20}
21
22direct_from_impl!(&'_ str);
23direct_from_impl!(Cow<'_, str>);
24direct_from_impl!(String);
25
26impl From<Box<str>> for crate::Atom {
27 fn from(s: Box<str>) -> Self {
28 global_atom(&s)
29 }
30}
31
32macro_rules! direct_from_impl_wtf8 {
33 ($T:ty) => {
34 impl From<$T> for Wtf8Atom {
35 fn from(s: $T) -> Self {
36 global_wtf8_atom(s.as_bytes())
37 }
38 }
39 };
40}
41
42direct_from_impl_wtf8!(&'_ str);
43direct_from_impl_wtf8!(Cow<'_, str>);
44direct_from_impl_wtf8!(String);
45direct_from_impl_wtf8!(&'_ Wtf8);
46direct_from_impl_wtf8!(Wtf8Buf);
47
48impl From<&Atom> for crate::Wtf8Atom {
49 fn from(s: &Atom) -> Self {
50 forget(s.clone());
51 Wtf8Atom {
52 unsafe_data: s.unsafe_data,
53 }
54 }
55}
56
57impl From<Atom> for crate::Wtf8Atom {
58 fn from(s: Atom) -> Self {
59 let s = ManuallyDrop::new(s);
60 Wtf8Atom {
61 unsafe_data: s.unsafe_data,
62 }
63 }
64}
65
66impl From<Box<str>> for crate::Wtf8Atom {
67 fn from(s: Box<str>) -> Self {
68 global_wtf8_atom(s.as_bytes())
69 }
70}