rusty_v8/
external_references.rs1use crate::support::intptr_t;
3use crate::AccessorNameGetterCallback;
4use crate::FunctionCallback;
5use crate::MessageCallback;
6
7#[derive(Clone, Copy)]
8pub union ExternalReference<'s> {
9 pub function: FunctionCallback,
10 pub getter: AccessorNameGetterCallback<'s>,
11 pub message: MessageCallback,
12}
13
14#[derive(Debug)]
15pub struct ExternalReferences {
16 null_terminated: Vec<intptr_t>,
17}
18
19unsafe impl Sync for ExternalReferences {}
20
21impl ExternalReferences {
22 pub fn new(refs: &[ExternalReference]) -> Self {
23 let null_terminated = refs
24 .iter()
25 .map(|&r| unsafe { std::mem::transmute(r) })
26 .chain(std::iter::once(0)) .collect::<Vec<intptr_t>>();
28 Self { null_terminated }
29 }
30
31 pub fn as_ptr(&self) -> *const intptr_t {
32 self.null_terminated.as_ptr()
33 }
34}
35
36impl std::ops::Deref for ExternalReferences {
37 type Target = [intptr_t];
38 fn deref(&self) -> &Self::Target {
39 &*self.null_terminated
40 }
41}
42
43impl std::borrow::Borrow<[intptr_t]> for ExternalReferences {
44 fn borrow(&self) -> &[intptr_t] {
45 &**self
46 }
47}