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
pub use core::{
convert::TryFrom,
fmt,
fmt::Write,
str::FromStr,
};
pub use alloc::{
boxed::Box,
format,
rc::Rc,
string::{
String,
ToString,
},
vec,
vec::Vec,
};
#[cfg(feature = "std")]
pub use std::collections::{
HashMap,
HashSet,
};
#[cfg(not(feature = "std"))]
pub use hashbrown::{
hash_map::HashMap,
hash_set::HashSet,
};
pub use crate::{
JSNumber,
JSString,
JSValue,
JSON,
};
#[macro_export]
macro_rules! derive_enum_from {
($enum:ident::$variant:ident) => {
derive_enum_from!($enum::$variant, $variant);
};
($enum:ident::$variant:ident, Box<$type:ty>) => {
impl From<$type> for $enum {
fn from(v: $type) -> Self {
$enum::$variant(Box::new(v))
}
}
};
($enum:ident::$variant:ident, $type:ty) => {
impl From<$type> for $enum {
fn from(v: $type) -> Self {
$enum::$variant(v)
}
}
};
($enum:ident::$variant:ident, T: Into<$type:ident>) => {
impl<T> From<T> for $enum
where
$type: From<T>,
{
fn from(val: T) -> Self {
let val = <$type as From<T>>::from(val);
$enum::$variant(val)
}
}
};
}