Comments (9)
I can give this a shot. Can you please explain a bit how this should be implemented and the API you are looking for? I'm not yet familiar with the async traits.
from gio.
Shouldn't AsyncBufRead
be implemented on PollableInputStream
instead as it's the one implementing AsyncRead
?
from gio.
No, and that one also only has an adapter that you can get from it to have an AsyncRead
. We can't implement it directly on our types :)
AsyncBufRead
(unlike AsyncRead
) can be implemented for the normal input streams. AsyncRead
requires an API where the buffers are owned by the caller while AsyncBufRead
allows the buffer to be owned by the callee. You could have an adapter that contains a vec and then hands out immutable slices to that vec whenever a read has finished (because g_input_stream_read()
requires ownership of the buffer it is impossible to implement AsyncRead
on it).
from gio.
it is impossible to implement AsyncRead on it
But AsyncBufRead
has a trait bound on AsyncRead
so the adapter will have to implement both traits. How will this work then?
from gio.
Ah I missed that. You would implement AsyncRead
indirectly then, with a copy from the internal buffer into the caller-provided buffer.
from gio.
Here is what I have so far for AsyncRead
: gdesmott@be9f0ad
Problem is the test is calling poll_read()
once which is returning Pending
but then seems stuck.
Isn't the Poll
from read_async_future
supposed to wake up cx
once its ready which would trigger a new poll from the executioner?
First time I'm actually writing futures code so I may have miss something. :)
from gio.
Answered there in the commit :)
from gio.
poll_read()
receives a Pin<&mut Self>
but I'm not able to get a &mut InputStreamAsyncBufRead
out of it as my type doesn't implement Unpin
. Is that normal?
As a result, I'm trying to workaround this immutability by wrapping the state in a Refcell
. I kinda works except when performing state switches as I need to deconstruct the state enum while it's borrowed, see gdesmott@84bd74d#diff-463b53a4eb9782d0f3c7dfb895572516R393
error[E0507]: cannot move out of dereference of `std::cell::RefMut<'_, input_stream::State>`
--> src/input_stream.rs:393:15
|
393 | match *state {
| ^^^^^^ help: consider borrowing here: `&*state`
394 | State::Waiting { buffer: buffer } => {
| ------
| |
| data moved here
| move occurs because `buffer` has type `std::vec::Vec<u8>`, which does not implement the `Copy` trait
Is there a better pattern to handle all this? Or should I just implement Unpin
on InputStreamAsyncBufRead
? I'm still not very clear on its exact semantic.
from gio.
You might want to use the pin_project
crate for this, or require Unpin
. Various existing future implementations in the futures
crate can probably be taken here as examples. There are IIRC a few that also have multiple states, for example and_then
:)
from gio.
Related Issues (20)
- Idea for "magical" strings HOT 6
- Add GPropertyAction HOT 3
- Unable to write bytes to IOStream using futures HOT 4
- How to convert Vec<GString> into Vec<String> HOT 6
- Missing Permission::new() HOT 5
- Manual bindings for functions with Cancellable args are inconsistent HOT 4
- Implement AppInfo::launch_uris_async
- Wrong mutability in UnixMountPoint HOT 1
- Don't require all users of `GioFuture` to depend on `fragile` HOT 1
- GIO is trying to list g_desktop_app_info* on macos and causing link failure HOT 1
- DataInputStream::read_until_async asserts when empty HOT 6
- Add check to ensure that no manual_trait is forgotten HOT 5
- ApplicationExt::connect_handle_local_options() is missing HOT 7
- ThreadedSocketService panics while accepting connection HOT 4
- Bind GIOChannel HOT 3
- How to use async reqwest HTTP client from gio event loop? HOT 3
- InetAddress <-> standard library IpAddr* types conversion
- `TimeVal` usage is wrong and maybe shouldn't be there at all HOT 1
- No TlsBackend? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gio.