Skip to content
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

Allow direct conversion for Document -> Response #30

Merged
merged 3 commits into from
Nov 22, 2020

Conversation

Alch-Emi
Copy link
Contributor

@Alch-Emi Alch-Emi commented Nov 20, 2020

This add From<Borrow<Document>> to Response, allowing users to call .into() on any reference to a Document. This means that when chaining methods together to build a document, .into() can simply be chained along. So this:

let doc = Document::new();
doc.add_text("hello")
   .add_text("world");
let resp = Response::document(doc);

can become this:

let resp = Document::new()
    .add_text("hello")
    .add_text("wello")
    .into();

This does also affect the Response::document method, but only to make it more general, so this isn't a breaking change.


This change is Reviewable

Also how did I not know about the Borrow trait until now???
This allows users to call &mut Document.into() in order to create a response, so that you
can do it right in the middle of one of those builder call chain thingies
@panicbit
Copy link
Owner

Thanks!

@panicbit panicbit merged commit 3a999a1 into panicbit:master Nov 22, 2020
@Alch-Emi Alch-Emi deleted the doc-into-req branch November 23, 2020 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants