Skip to content

Commit

Permalink
Add blanket impl for the 'Resource' trait (denoland#3903)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Feb 8, 2020
1 parent d7edf39 commit 25467aa
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 21 deletions.
3 changes: 0 additions & 3 deletions cli/ops/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::http_util::HttpBody;
use crate::ops::minimal_op;
use crate::state::ThreadSafeState;
use deno_core::ErrBox;
use deno_core::Resource;
use deno_core::*;
use futures::future::FutureExt;
use futures::ready;
Expand Down Expand Up @@ -86,8 +85,6 @@ pub enum StreamResource {
ChildStderr(tokio::process::ChildStderr),
}

impl Resource for StreamResource {}

/// `DenoAsyncRead` is the same as the `tokio_io::AsyncRead` trait
/// but uses an `ErrBox` error instead of `std::io:Error`
pub trait DenoAsyncRead {
Expand Down
3 changes: 0 additions & 3 deletions cli/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::deno_error::bad_resource;
use crate::ops::json_op;
use crate::resolve_addr::resolve_addr;
use crate::state::ThreadSafeState;
use deno_core::Resource;
use deno_core::*;
use futures::future::FutureExt;
use std;
Expand Down Expand Up @@ -226,8 +225,6 @@ struct TcpListenerResource {
local_addr: SocketAddr,
}

impl Resource for TcpListenerResource {}

impl Drop for TcpListenerResource {
fn drop(&mut self) {
self.wake_task();
Expand Down
2 changes: 0 additions & 2 deletions cli/ops/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ struct PluginResource {
ops: HashMap<String, OpId>,
}

impl Resource for PluginResource {}

struct InitContext {
ops: HashMap<String, Box<OpDispatcher>>,
}
Expand Down
2 changes: 0 additions & 2 deletions cli/ops/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ struct ChildResource {
child: tokio::process::Child,
}

impl Resource for ChildResource {}

fn op_run(
state: &ThreadSafeState,
args: Value,
Expand Down
3 changes: 0 additions & 3 deletions cli/ops/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::ops::json_op;
use crate::repl;
use crate::repl::Repl;
use crate::state::ThreadSafeState;
use deno_core::Resource;
use deno_core::*;
use std::sync::Arc;
use std::sync::Mutex;
Expand All @@ -23,8 +22,6 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {

struct ReplResource(Arc<Mutex<Repl>>);

impl Resource for ReplResource {}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct ReplStartArgs {
Expand Down
5 changes: 0 additions & 5 deletions cli/ops/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use super::dispatch_json::Deserialize;
#[cfg(unix)]
use crate::deno_error::bad_resource;
#[cfg(unix)]
use deno_core::Resource;
#[cfg(unix)]
use futures::future::{poll_fn, FutureExt};
#[cfg(unix)]
use serde_json;
Expand Down Expand Up @@ -39,9 +37,6 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
/// The second element is the waker of polling future.
pub struct SignalStreamResource(pub Signal, pub Option<Waker>);

#[cfg(unix)]
impl Resource for SignalStreamResource {}

#[cfg(unix)]
#[derive(Deserialize)]
struct BindSignalArgs {
Expand Down
3 changes: 0 additions & 3 deletions cli/ops/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::deno_error::ErrorKind;
use crate::ops::json_op;
use crate::resolve_addr::resolve_addr;
use crate::state::ThreadSafeState;
use deno_core::Resource;
use deno_core::*;
use futures::future::FutureExt;
use std;
Expand Down Expand Up @@ -185,8 +184,6 @@ pub struct TlsListenerResource {
local_addr: SocketAddr,
}

impl Resource for TlsListenerResource {}

impl Drop for TlsListenerResource {
fn drop(&mut self) {
self.wake_task();
Expand Down
1 change: 1 addition & 0 deletions core/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ impl ResourceTable {
/// that allows to cast resource to concrete type in `TableResource::get`
/// and `TableResource::get_mut` methods.
pub trait Resource: Downcast + Any + Send {}
impl<T> Resource for T where T: Downcast + Any + Send {}
impl_downcast!(Resource);

0 comments on commit 25467aa

Please sign in to comment.