From 435330b4153fff545a063efe8e5d2617abb0b1ef Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Fri, 20 Nov 2020 09:40:57 -0500 Subject: [PATCH] Made Request::document a bit more generic Also how did I not know about the Borrow trait until now??? --- src/types/body.rs | 8 +++++--- src/types/response.rs | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/types/body.rs b/src/types/body.rs index d2da102..a7481c3 100644 --- a/src/types/body.rs +++ b/src/types/body.rs @@ -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), } -impl From for Body { - fn from(document: Document) -> Self { - Self::from(document.to_string()) +impl> From for Body { + fn from(document: D) -> Self { + Self::from(document.borrow().to_string()) } } diff --git a/src/types/response.rs b/src/types/response.rs index 991d511..ce1b5b6 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -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) -> Self { Self::success_with_body(&GEMINI_MIME, document) }