1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::{Atom, Ctx, FromAtom, IntoAtom, Result, StdString, String, Value};
impl<'js> FromAtom<'js> for Atom<'js> {
fn from_atom(atom: Atom<'js>) -> Result<Self> {
Ok(atom)
}
}
impl<'js> FromAtom<'js> for Value<'js> {
fn from_atom(atom: Atom<'js>) -> Result<Self> {
atom.to_value()
}
}
impl<'js> FromAtom<'js> for String<'js> {
fn from_atom(atom: Atom<'js>) -> Result<Self> {
atom.to_js_string()
}
}
impl<'js> FromAtom<'js> for StdString {
fn from_atom(atom: Atom<'js>) -> Result<Self> {
atom.to_string()
}
}
impl<'js> IntoAtom<'js> for Atom<'js> {
fn into_atom(self, _: Ctx<'js>) -> Atom<'js> {
self
}
}
impl<'js> IntoAtom<'js> for Value<'js> {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js> {
Atom::from_value(ctx, &self)
}
}
impl<'js> IntoAtom<'js> for &str {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js> {
Atom::from_str(ctx, self)
}
}
impl<'js> IntoAtom<'js> for StdString {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js> {
Atom::from_str(ctx, &self)
}
}
impl<'js> IntoAtom<'js> for &StdString {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js> {
Atom::from_str(ctx, self)
}
}
macro_rules! into_atom_impls {
($($from:ident: $($type:ident)*,)*) => {
$(
$(
impl<'js> IntoAtom<'js> for $type {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js> {
Atom::$from(ctx, self as _)
}
}
)*
)*
};
}
into_atom_impls! {
from_bool: bool,
from_u32: u8 u16 u32,
from_i32: i8 i16 i32,
from_f64: f32 f64,
}