-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add a mid-level file-rfc #76
Conversation
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.
LGTM!
I'm OK with the BlobLike
trait because while we went the other way with web-sys
, I'm not convinced that all the same arguments made there apply directly here. For example, with web-sys
we are exactly exposing the JS API as close as we can. With Gloo, we are actively trying to make things more Rust-y.
I'll wait for @Pauan's feedback and approval before submitting an implementation PR. |
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.
This feels solid for a mid-level API!
One question tho: I'm wondering tho if having Futures be part of the mid-level API makes the most sense, or if that would actually be better suited as the end-user interface we expose in the high-level API.
@yoshuawuyts Having futures in the same API feels right to me, because It still maps very closely to the JS API. I don't have strong feelings about this though so if the group wants to be extra conservative and only do the callback based API at first I'm fine with that. We could later open a new proposal that would extend the mid-level API with futures OR create a new high level API with futures. |
Yeah, I'm definitely feeling like having a high-level API on top of this would be a great fit. For example Also IntoIterator, Add and other might have a place. I feel Futures provide a similar high-level interface on top of the mid-level API. But yeah, don't feel too strongly about this. Just curious how we're envisioning we slice this up (: |
rfcs/001-mid-level-file-api.md
Outdated
|
||
## The API | ||
|
||
First we have `FileList` which is simply a list of `File`s. This is an opaque struct that offers a way to iterate over `Files` and get individual files by index: |
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.
Is there a reason this can't internally be a Vec<File>
, and then impl Deref<Target = [File]>
?
Even the current editor's draft says that uses of FileList
are getting replaced with Array
(which would get translated into Vec
in Rust).
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.
This would require iterating the internal js_sys::FileList
and collecting the files into a Vec
. Are we sure we want the user to pay this price each time a FileList
is constructed? I personally think an into_vec
API is more appropriate since it conveys that there will be an additional allocation.
In any effect, it's possible to add these in a backward compatible way. Can we push this off to another PR/RFC?
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 don't think it's possible to add it in a backwards compatible way, since a Vec
would have a different API.
And since (apparently) FileList
is being phased out in favor of a normal JS Array
, I think Vec
is quite appropriate.
In fact, we may even want to skip the FileList
type entirely and just return Vec<File>
.
That also makes it pretty clear that there is an allocation (since Vec
obviously allocates).
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.
@Pauan Can you explain how the API would need to be different? I'm sorry, I don't really get the reason for this given the cost users would have to pay.
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.
Basically, rather than having a method which returns a FileList
, it would instead return Vec<File>
.
That means we don't actually need FileList
at all.
The cost is quite small, but the benefits are significant: things are drastically simplified, and users get to use the slice methods for free.
(By the way, sorry for the delay on this, I recently caught a nasty cold) |
@Pauan @fitzgen I've made some final changes including removing the builders for File and Blob since the constructors are now now that unwieldy. I'd like to merge this. I know there's one concern not fully addressed from @Pauan, but I think the proposal is in a good state and ready to be implemented. Thoughts? |
I'm happy with it. Let's address the last outstanding concern and get this merged! |
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 would really like us to explore Vec<File>
instead of FileList
, but I don't want to block on it, since everything else seems good.
@Pauan I'm not convinced. If the user wants a |
Yes of course the user can do that... but the point is to simplify things. Not needing to have the It's less things to learn, less things to worry about. It's also extremely Rusty (since And as the W3C page says, they're deprecating So I think you need to do a better job of justifying why we need |
Yes, that's basically my proposal. Though we haven't yet decided on how this will interact with |
|
rendered
As we've settled on an RFC process, I'd like to continue #50 here.