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
Implement From<String> for Document #10
Implement From<String> for Document #10
Conversation
Currently, one cannot create a Document from a String, as is the case when reading a response from Hyper into a String. With From<String>, this is now possible.
Thanks for the PR! Do we really need a
What do you think? |
I think we should instead have a With that, you would be able to write:
and reduce the allocations to half. |
I like your last suggestion with Regarding the first comment, you can't currently do
as you quickly run into lifetime errors. I'm not quite sure why but the error is:
The current implementation is
I tried adding 'a to the argument of from, but that didn't change anything either. |
I'll only have time to do it later this week, or if you want to, you could send a PR. A test would also be nice (You could use I believe the signature would look like:
Ah, looks like just
|
Also, I just saw you're using |
I was using 0.2.2 as i couldn't get my string coerced correctly on 3.0, and I found an other project using select and hyper with 0.2.2 which worked. Could you explain why the &* is needed? |
|
@aleksanb @LeMoussel I'm not sure myself why the extra
This compiles:
While this doesn't:
|
The chapter about Deref Coercions in the Rust Book doesn't mention this case: https://doc.rust-lang.org/book/deref-coercions.html. |
Here's a sample implementation of the from_read version:
The unwrap should be replaced by something, but the error type of the tendril is just the tendril itself, so i'm unsure what we should map the error to. |
Ah,
|
This is how
|
I've put the new pull request up on https://github.com/utkarshkukreti/select.rs/pull/13/files, |
Currently, one cannot create a Document from a String,
as is the case when reading a response from Hyper into a String.
With From, this is now possible.
Example of new allowed behaviour: