Made Request::document a bit more generic
Also how did I not know about the Borrow trait until now???
This commit is contained in:
parent
0ca71e46c9
commit
435330b415
|
@ -2,6 +2,8 @@ use tokio::io::AsyncRead;
|
||||||
#[cfg(feature="serve_dir")]
|
#[cfg(feature="serve_dir")]
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
use crate::types::Document;
|
use crate::types::Document;
|
||||||
|
|
||||||
pub enum Body {
|
pub enum Body {
|
||||||
|
@ -9,9 +11,9 @@ pub enum Body {
|
||||||
Reader(Box<dyn AsyncRead + Send + Sync + Unpin>),
|
Reader(Box<dyn AsyncRead + Send + Sync + Unpin>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Document> for Body {
|
impl<D: Borrow<Document>> From<D> for Body {
|
||||||
fn from(document: Document) -> Self {
|
fn from(document: D) -> Self {
|
||||||
Self::from(document.to_string())
|
Self::from(document.borrow().to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
use uriparse::URIReference;
|
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)
|
Self::success_with_body(&GEMINI_MIME, document)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue