Made Request::document a bit more generic

Also how did I not know about the Borrow trait until now???
This commit is contained in:
Emi Tatsuo 2020-11-20 09:40:57 -05:00
parent 0ca71e46c9
commit 435330b415
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
2 changed files with 7 additions and 4 deletions

View File

@ -2,6 +2,8 @@ use tokio::io::AsyncRead;
#[cfg(feature="serve_dir")]
use tokio::fs::File;
use std::borrow::Borrow;
use crate::types::Document;
pub enum Body {
@ -9,9 +11,9 @@ pub enum Body {
Reader(Box<dyn AsyncRead + Send + Sync + Unpin>),
}
impl From<Document> for Body {
fn from(document: Document) -> Self {
Self::from(document.to_string())
impl<D: Borrow<Document>> From<D> for Body {
fn from(document: D) -> Self {
Self::from(document.borrow().to_string())
}
}

View File

@ -1,4 +1,5 @@
use std::convert::TryInto;
use std::borrow::Borrow;
use anyhow::*;
use uriparse::URIReference;
@ -19,7 +20,7 @@ impl Response {
}
}
pub fn document(document: Document) -> Self {
pub fn document(document: impl Borrow<Document>) -> Self {
Self::success_with_body(&GEMINI_MIME, document)
}