neon/types_impl/extract/
private.rs

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use std::sync::Arc;

use crate::{
    context::FunctionContext,
    handle::{Handle, Root},
    object::Object,
    result::{NeonResult, Throw},
    types::{
        buffer::Binary,
        extract::{ArrayBuffer, Buffer, Date, Error, TryIntoJs},
        JsTypedArray, Value,
    },
};

pub trait Sealed {}

pub trait FromArgsInternal<'cx>: Sized {
    fn from_args(cx: &mut FunctionContext<'cx>) -> NeonResult<Self>;

    fn from_args_opt(cx: &mut FunctionContext<'cx>) -> NeonResult<Option<Self>>;
}

macro_rules! impl_sealed {
    ($ty:ident) => {
        impl Sealed for $ty {}
    };

    ($($ty:ident),* $(,)*) => {
        $(
            impl_sealed!($ty);
        )*
    }
}

impl Sealed for () {}

impl Sealed for &str {}

impl Sealed for &String {}

impl<'cx, V: Value> Sealed for Handle<'cx, V> {}

impl<O: Object> Sealed for Root<O> {}

impl<T> Sealed for Option<T> {}

impl<T, E> Sealed for Result<T, E> {}

impl<T> Sealed for Vec<T>
where
    JsTypedArray<T>: Value,
    T: Binary,
{
}

impl<T> Sealed for Box<[T]>
where
    JsTypedArray<T>: Value,
    T: Binary,
{
}

impl<T, const N: usize> Sealed for [T; N]
where
    JsTypedArray<T>: Value,
    T: Binary,
{
}

impl<T> Sealed for &Vec<T>
where
    JsTypedArray<T>: Value,
    T: Binary,
{
}

impl<T> Sealed for &[T]
where
    JsTypedArray<T>: Value,
    T: Binary,
{
}

impl<'cx, T> Sealed for Arc<T> where for<'a> &'a T: TryIntoJs<'cx> {}

impl<'cx, T> Sealed for Box<T> where T: TryIntoJs<'cx> {}

impl_sealed!(
    u8,
    u16,
    u32,
    i8,
    i16,
    i32,
    f32,
    f64,
    bool,
    String,
    Date,
    Buffer,
    ArrayBuffer,
    Throw,
    Error,
);