Add From<Borrow<Document>> to Response

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
This commit is contained in:
Emi Tatsuo 2020-11-20 09:51:37 -05:00
parent 435330b415
commit 3296d00ec3
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
2 changed files with 10 additions and 6 deletions

View File

@ -18,9 +18,7 @@ async fn main() -> Result<()> {
fn handle_request(_request: Request) -> BoxFuture<'static, Result<Response>> {
async move {
let mut document = Document::new();
document
let response = Document::new()
.add_preformatted(include_str!("northstar_logo.txt"))
.add_blank_line()
.add_link("https://docs.rs/northstar", "Documentation")
@ -43,9 +41,9 @@ fn handle_request(_request: Request) -> BoxFuture<'static, Result<Response>> {
.add_preformatted_with_alt("sh", concat!(
"mkdir cert && cd cert\n",
"openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365",
));
Ok(Response::document(document))
))
.into();
Ok(response)
}
.boxed()
}

View File

@ -95,3 +95,9 @@ impl Response {
self.body.take()
}
}
impl<D: Borrow<Document>> From<D> for Response {
fn from(doc: D) -> Self {
Self::document(doc)
}
}