-
Notifications
You must be signed in to change notification settings - Fork 236
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
Async support #450
Async support #450
Conversation
Codecov Report
@@ Coverage Diff @@
## master #450 +/- ##
==========================================
+ Coverage 51.33% 51.49% +0.16%
==========================================
Files 28 29 +1
Lines 13312 13435 +123
==========================================
+ Hits 6834 6919 +85
- Misses 6478 6516 +38
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Will need a few days to fully review.. just leaving a few comments for now. |
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 think most of this PR looks good, thank you very much for adapting my work!
I haven't yet compared the old and new code exactly to make 100% sure they match, but they seem to match. There are a few changes I'd like to see, most notably the macros being moved to their own module to improve readability and get the async
implementation out of buffered_reader.rs
.
@@ -12,6 +12,216 @@ use crate::events::Event; | |||
use crate::name::QName; | |||
use crate::reader::{is_whitespace, BangType, ReadElementState, Reader, XmlSource}; | |||
|
|||
macro_rules! impl_buffered_source { |
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 macro might be better in a separate module as it's used for both sync and async implementations of buffered IO.
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 know... Having macro in this place first of all indicates that it implements a buffering reader. Because "buffering" trait of this macro seems to me more important, than "async" trait, it is defined here. Moving it into another module will break the explicit link with that usage place, as I think
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.
It's your choice in the end. Keeping it here would work too.
@@ -127,11 +127,152 @@ macro_rules! configure_methods { | |||
}; | |||
} | |||
|
|||
macro_rules! read_event_impl { |
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.
All of these macros should be moved into a separate module (see also my comment in buffered_reader.rs
).
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.
The advantage of their definition there is that here is one usage place and those macros is very tied to functions where they used. I think it will be better to leave them here.
@@ -23,6 +24,8 @@ pretty_assertions = "1.2" | |||
regex = "1" | |||
serde = { version = "1.0", features = ["derive"] } | |||
serde-value = "0.7" | |||
tokio = { version = "1.20", default-features = false, features = ["macros", "rt"] } |
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 know you didn't want to have support for from_file
functions for the async reader, but I think we should still have at least one test which actually reads from a file, which would require the fs
feature here. At least in dev-dependencies
I think it's okay to have more features.
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.
Actually, I do not see why we need to test actual reading from a file. I doubt that this test could catch something that is not catched by the test that read from memory. For example, we also does not have tests for sync reader that reads from a file (we have only two examples for that).
I really wish we could try out the internal buffering idea (no more So I would say I'm -0, I won't block it but I'm not thrilled about that particular change to be honest. |
This commit only moves code and will allow to share the code with async implementations It is better to review it in the TortoiseGitMerge with whitespace changes ignored
I think that the idea to allow the user to manage the buffer with the event content as he wish has they own benefits. Actually, that approach very similar to how So we could investigate that idea, and maybe even provide a special buffering reader for users that do not want to manage the buffer himself, but we should keep the current API. That API allows to apply the reader as an operator to a buffer and create events over it, which does not tied to the reader itself, so it can be even destroyed if it is not required anymore. Since there are no fundamental objections, I think I will merge it in a few hours. |
@999eagle Do you feel like this feature is living up to your expectations? Any issues with it in practice? |
First of all, I would like to thank @999eagle for her work. It was very useful for quickly obtaining a working result and its iterative improvement.
After week of experimenting and prepare work I think, that the result suits me. I tried to focus on those points:
quick-xml/src/reader/mod.rs
Lines 324 to 326 in 9ccc686
I have considered several options
SliceReader
,BufferedReader
andAsyncReader
:SyncReader
andAsyncReader
SyncReader
, so...TokioAdapter
(formerAsyncReader
)Reader<R>
futures
were unsuccessful -- API differs a little. Besides, there is nothing difficult in principle, but so far it seems that it is possible to do without it as as there are adaptersAs it seemed, all realization differs slightly. I especially like the 4th option, as it eliminates the need for a long type if you need to pass
Reader
to the function. I think, I'll make also another PR with that variant.I decided to not implement
from_file
for async reader, because it is required additional tokio feature and it seems that it can be easely done outside the crate.Also, I did not implement
read_text_into_async
API, because it available not on all readers and I think, it should be reworked to return all intermediate notes as text as required for #257 and also was discussed in #154.I'm not sure, whether we have to
Send
for inner type, as was originally implemented by @999eagle in #417, currently I do not require that. It seems, that compiler should automatically guarantee that when it can, but how to check that?@999eagle, could you also review that?
Closes #417
Closes #425