diff options
Diffstat (limited to 'test_plugin/src/lib.rs')
-rw-r--r-- | test_plugin/src/lib.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs index 37868b310..781bc4259 100644 --- a/test_plugin/src/lib.rs +++ b/test_plugin/src/lib.rs @@ -13,15 +13,16 @@ pub fn deno_plugin_init(interface: &mut dyn Interface) { fn op_test_sync( _interface: &mut dyn Interface, data: &[u8], - zero_copy: Option<ZeroCopyBuf>, + zero_copy: &mut [ZeroCopyBuf], ) -> Op { - if let Some(buf) = zero_copy { - let data_str = std::str::from_utf8(&data[..]).unwrap(); + let data_str = std::str::from_utf8(&data[..]).unwrap(); + let zero_copy = zero_copy.to_vec(); + if !zero_copy.is_empty() { + println!("Hello from plugin. data: {}", data_str); + } + for (idx, buf) in zero_copy.iter().enumerate() { let buf_str = std::str::from_utf8(&buf[..]).unwrap(); - println!( - "Hello from plugin. data: {} | zero_copy: {}", - data_str, buf_str - ); + println!("zero_copy[{}]: {}", idx, buf_str); } let result = b"test"; let result_box: Buf = Box::new(*result); @@ -31,16 +32,17 @@ fn op_test_sync( fn op_test_async( _interface: &mut dyn Interface, data: &[u8], - zero_copy: Option<ZeroCopyBuf>, + zero_copy: &mut [ZeroCopyBuf], ) -> Op { - let data_str = std::str::from_utf8(&data[..]).unwrap().to_string(); + let zero_copy = zero_copy.to_vec(); + if !zero_copy.is_empty() { + let data_str = std::str::from_utf8(&data[..]).unwrap().to_string(); + println!("Hello from plugin. data: {}", data_str); + } let fut = async move { - if let Some(buf) = zero_copy { + for (idx, buf) in zero_copy.iter().enumerate() { let buf_str = std::str::from_utf8(&buf[..]).unwrap(); - println!( - "Hello from plugin. data: {} | zero_copy: {}", - data_str, buf_str - ); + println!("zero_copy[{}]: {}", idx, buf_str); } let (tx, rx) = futures::channel::oneshot::channel::<Result<(), ()>>(); std::thread::spawn(move || { |