summaryrefslogtreecommitdiff
path: root/core/examples/hello_world.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-05-06 19:32:03 +0200
committerGitHub <noreply@github.com>2021-05-06 19:32:03 +0200
commit1e8e44f4c31688ac55100f96bdab27723eb6e575 (patch)
tree820c3b61ded766ecb912eefddaae4894e399555c /core/examples/hello_world.rs
parentf208e6a26f3c21c25dbfcfe29491a6f5660c999d (diff)
refactor(ops): replace `ZeroCopyBuf` arg by 2nd generic deserializable arg (#10448)
Diffstat (limited to 'core/examples/hello_world.rs')
-rw-r--r--core/examples/hello_world.rs29
1 files changed, 16 insertions, 13 deletions
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<String>, zero_copy| {
- let mut out = std::io::stdout();
+ op_sync(
+ |_state, msg: Option<String>, zero_copy: Option<ZeroCopyBuf>| {
+ 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<f64>, _| {
+ op_sync(|_state, nums: Vec<f64>, _: ()| {
// Sum inputs
let sum = nums.iter().fold(0.0, |a, v| a + v);
// return as a Result<f64, AnyError>