diff --git a/src/util.rs b/src/files.rs similarity index 90% rename from src/util.rs rename to src/files.rs index a18a0e2..5ab4f1d 100644 --- a/src/util.rs +++ b/src/files.rs @@ -3,17 +3,13 @@ //! ⚠️ Docs still under construction & API not yet stable ⚠️ #![allow(missing_docs)] -#[cfg(feature="serve_dir")] use std::path::{Path, PathBuf}; -#[cfg(feature="serve_dir")] use tokio::{ fs::{self, File}, io, }; -#[cfg(feature="serve_dir")] use crate::types::Response; -#[cfg(feature="serve_dir")] pub async fn serve_file>(path: P, mime: &str) -> Response { let path = path.as_ref(); @@ -31,7 +27,6 @@ pub async fn serve_file>(path: P, mime: &str) -> Response { Response::success(mime, file) } -#[cfg(feature="serve_dir")] pub async fn serve_dir, P: AsRef>(dir: D, virtual_path: &[P]) -> Response { debug!("Dir: {}", dir.as_ref().display()); let dir = dir.as_ref(); @@ -85,7 +80,6 @@ pub async fn serve_dir, P: AsRef>(dir: D, virtual_path: &[P serve_dir_listing(path, virtual_path).await } -#[cfg(feature="serve_dir")] async fn serve_dir_listing, B: AsRef>(path: P, virtual_path: &[B]) -> Response { let mut dir = match fs::read_dir(path.as_ref()).await { Ok(dir) => dir, @@ -126,7 +120,6 @@ async fn serve_dir_listing, B: AsRef>(path: P, virtual_path document.into() } -#[cfg(feature="serve_dir")] pub fn guess_mime_from_path>(path: P) -> &'static str { let path = path.as_ref(); let extension = path.extension().and_then(|s| s.to_str()); @@ -142,7 +135,6 @@ pub fn guess_mime_from_path>(path: P) -> &'static str { mime_guess::from_ext(extension).first_raw().unwrap_or("application/octet-stream") } -#[cfg(feature="serve_dir")] /// Print a warning to the log asking to file an issue and respond with "Unexpected Error" pub (crate) fn warn_unexpected(err: impl std::fmt::Debug, path: &Path, line: u32) -> Response { warn!( @@ -157,19 +149,3 @@ pub (crate) fn warn_unexpected(err: impl std::fmt::Debug, path: &Path, line: u32 ); Response::temporary_failure("Unexpected error") } - -/// A convenience trait alias for `AsRef + Into`, -/// most commonly used to accept `&str` or `String`: -/// -/// `Cowy` ⇔ `AsRef + Into` -pub trait Cowy -where - Self: AsRef + Into, - T: ToOwned + ?Sized, -{} - -impl Cowy for C -where - C: AsRef + Into, - T: ToOwned + ?Sized, -{} diff --git a/src/lib.rs b/src/lib.rs index b9ba4e2..993108e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,7 +235,8 @@ use rustls::Session; mod types; mod handling; -pub mod util; +#[cfg(feature = "serve_dir")] +pub mod files; pub mod routing; #[cfg(feature = "ratelimiting")] mod ratelimiting;