wry_bindgen_core/
batchable.rs1use alloc::string::String;
2use alloc::vec::Vec;
3
4use wry_bindgen_runtime::wire::{BinaryDecode, BinaryEncode, EncodedData, JsRef, ObjectHandle};
5
6use crate::Runtime;
7
8pub trait BatchableResult: BinaryDecode {
9 fn try_placeholder(_: &mut Runtime) -> Option<Self> {
10 None
11 }
12}
13
14#[derive(Clone, Copy, Default)]
15pub struct RequireFlush;
16
17impl BinaryEncode for RequireFlush {
18 fn encode(self, encoder: &mut EncodedData) {
19 encoder.mark_needs_flush();
20 }
21}
22
23impl BatchableResult for () {
24 fn try_placeholder(_: &mut Runtime) -> Option<Self> {
25 Some(())
26 }
27}
28
29macro_rules! impl_value_type {
30 ($($ty:ty),*) => {
31 $(impl BatchableResult for $ty {})*
32 };
33}
34
35impl_value_type!(
36 bool, char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, isize, usize, f32, f64, String
37);
38
39impl<T: BinaryDecode> BatchableResult for Option<T> {}
40
41impl<T: BinaryDecode, E: BinaryDecode> BatchableResult for Result<T, E> {}
42
43impl<T: BinaryDecode> BatchableResult for Vec<T> {}
44
45impl BatchableResult for JsRef {
46 fn try_placeholder(batch: &mut Runtime) -> Option<Self> {
47 Some(batch.next_placeholder_ref())
48 }
49}
50
51impl BatchableResult for ObjectHandle {}