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:
parent
435330b415
commit
3296d00ec3
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue