-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: Add ResourceTable #3150
core: Add ResourceTable #3150
Conversation
df91327
to
bc24532
Compare
} | ||
|
||
/// Abstract type representing resource in Deno. | ||
pub trait Resource: Downcast + Any + Send { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried implementing downcasting manually, but got such errors:
error[E0038]: the trait `resources::Resource` cannot be made into an object
--> core/resources.rs:61:3
|
61 | pub fn add(&mut self, resource: Box<dyn Resource>) -> ResourceId {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `resources::Resource` cannot be made into an object
|
= note: method `downcast_ref` has generic type parameters
= note: method `downcast_mut` has generic type parameters
That's why I used Downcast
trait from downcast-rs
crate.
) | ||
let fut = futures::future::poll_fn(move || { | ||
let mut table = get_resource_table(); | ||
let stream = table.get_mut::<TcpStream>(rid)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be awesome if we could do something like:
let stream = table.get_mut::<dyn AsyncWrite>(rid)?;
stream.poll_write(&zero_copy_buf)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you for this important work!
I defer to @piscisaureus to approve and land.
Cool, though we shouldn't land it until we figure out how to implement |
The way you handled it in the example is good. |
Can't be translated to CLI though, PTAL at this comment |
I don't understand why it can't work in the CLI. It's the same operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscisaureus approves too - thanks @bartlomieju !
Closes #3134
CC @ry