From b2036a4db71afd67a78f932528143fb07faea538 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 16 Nov 2021 09:02:28 -0500 Subject: refactor: re-export anyhow from deno_core (#12777) --- core/examples/http_bench_json_ops.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'core/examples') diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 6f14f558c..641483b0b 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -1,5 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use deno_core::error::AnyError; +use deno_core::anyhow::Error; use deno_core::AsyncRefCell; use deno_core::AsyncResult; use deno_core::CancelHandle; @@ -12,7 +12,6 @@ use deno_core::ResourceId; use deno_core::ZeroCopyBuf; use std::cell::RefCell; use std::env; -use std::io::Error; use std::net::SocketAddr; use std::rc::Rc; use tokio::io::AsyncReadExt; @@ -43,7 +42,7 @@ struct TcpListener { } impl TcpListener { - async fn accept(self: Rc) -> Result { + async fn accept(self: Rc) -> Result { let cancel = RcRef::map(&self, |r| &r.cancel); let stream = self.inner.accept().try_or_cancel(cancel).await?.0.into(); Ok(stream) @@ -57,7 +56,7 @@ impl Resource for TcpListener { } impl TryFrom for TcpListener { - type Error = Error; + type Error = std::io::Error; fn try_from( std_listener: std::net::TcpListener, ) -> Result { @@ -78,21 +77,18 @@ struct TcpStream { } impl TcpStream { - async fn read( - self: Rc, - mut buf: ZeroCopyBuf, - ) -> Result { + async fn read(self: Rc, mut buf: ZeroCopyBuf) -> Result { let mut rd = RcRef::map(&self, |r| &r.rd).borrow_mut().await; let cancel = RcRef::map(self, |r| &r.cancel); rd.read(&mut buf) .try_or_cancel(cancel) .await - .map_err(AnyError::from) + .map_err(Error::from) } - async fn write(self: Rc, buf: ZeroCopyBuf) -> Result { + async fn write(self: Rc, buf: ZeroCopyBuf) -> Result { let mut wr = RcRef::map(self, |r| &r.wr).borrow_mut().await; - wr.write(&buf).await.map_err(AnyError::from) + wr.write(&buf).await.map_err(Error::from) } } @@ -129,11 +125,7 @@ fn create_js_runtime() -> JsRuntime { runtime } -fn op_listen( - state: &mut OpState, - _: (), - _: (), -) -> Result { +fn op_listen(state: &mut OpState, _: (), _: ()) -> Result { log::debug!("listen"); let addr = "127.0.0.1:4544".parse::().unwrap(); let std_listener = std::net::TcpListener::bind(&addr)?; @@ -147,7 +139,7 @@ async fn op_accept( state: Rc>, rid: ResourceId, _: (), -) -> Result { +) -> Result { log::debug!("accept rid={}", rid); let listener = state.borrow().resource_table.get::(rid)?; -- cgit v1.2.3