wry_bindgen/encode/
values.rs1use core::marker::PhantomData;
4
5use wry_bindgen_core::Runtime;
6
7use crate::Closure;
8use crate::ipc::{DecodeError, DecodedData, EncodedData};
9use crate::value::JsValue;
10
11use super::{BatchableResult, BinaryDecode, BinaryEncode, EncodeTypeDef, JsRef};
12
13impl EncodeTypeDef for JsValue {
14 fn encode_type_def(encoder: &mut crate::__rt::TypeDef) {
15 <JsRef as EncodeTypeDef>::encode_type_def(encoder);
16 }
17}
18
19impl BinaryEncode for JsValue {
20 fn encode(self, encoder: &mut EncodedData) {
21 self.js_ref().encode(encoder);
22 }
23}
24
25impl BinaryDecode for JsValue {
26 fn decode(decoder: &mut DecodedData) -> Result<Self, DecodeError> {
27 <JsRef as BinaryDecode>::decode(decoder).map(JsValue::from_ref)
28 }
29}
30
31impl BatchableResult for JsValue {
32 fn try_placeholder(batch: &mut Runtime) -> Option<Self> {
33 <JsRef as BatchableResult>::try_placeholder(batch).map(JsValue::from_ref)
34 }
35}
36
37impl<F: ?Sized> BatchableResult for Closure<F> {
38 fn try_placeholder(batch: &mut Runtime) -> Option<Self> {
39 Some(Closure {
40 _phantom: PhantomData,
41 callback: crate::closure::CallbackOwnership::None,
42 value: JsValue::try_placeholder(batch)?,
43 })
44 }
45}