From 1e8e44f4c31688ac55100f96bdab27723eb6e575 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 6 May 2021 19:32:03 +0200 Subject: refactor(ops): replace `ZeroCopyBuf` arg by 2nd generic deserializable arg (#10448) --- core/examples/hello_world.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'core/examples/hello_world.rs') diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index a9d2934f6..c2b2a2606 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -4,6 +4,7 @@ use deno_core::op_sync; use deno_core::JsRuntime; +use deno_core::ZeroCopyBuf; use std::io::Write; fn main() { @@ -26,21 +27,23 @@ fn main() { // The op_fn callback takes a state object OpState, // a structured arg of type `T` and an optional ZeroCopyBuf, // a mutable reference to a JavaScript ArrayBuffer - op_sync(|_state, msg: Option, zero_copy| { - let mut out = std::io::stdout(); + op_sync( + |_state, msg: Option, zero_copy: Option| { + let mut out = std::io::stdout(); - // Write msg to stdout - if let Some(msg) = msg { - out.write_all(msg.as_bytes()).unwrap(); - } + // Write msg to stdout + if let Some(msg) = msg { + out.write_all(msg.as_bytes()).unwrap(); + } - // Write the contents of every buffer to stdout - if let Some(buf) = zero_copy { - out.write_all(&buf).unwrap(); - } + // Write the contents of every buffer to stdout + if let Some(buf) = zero_copy { + out.write_all(&buf).unwrap(); + } - Ok(()) // No meaningful result - }), + Ok(()) // No meaningful result + }, + ), ); // Register the JSON op for summing a number array. @@ -49,7 +52,7 @@ fn main() { // The op_sync function automatically deserializes // the first ZeroCopyBuf and serializes the return value // to reduce boilerplate - op_sync(|_state, nums: Vec, _| { + op_sync(|_state, nums: Vec, _: ()| { // Sum inputs let sum = nums.iter().fold(0.0, |a, v| a + v); // return as a Result -- cgit v1.2.3