From e56691bcf23b4a9b37dc42823562fef9e8f4c514 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 6 Mar 2019 23:39:08 -0800 Subject: [PATCH] rename to Files --- Cargo.toml | 2 +- {actix-staticfiles => actix-files}/CHANGES.md | 0 {actix-staticfiles => actix-files}/Cargo.toml | 2 +- {actix-staticfiles => actix-files}/README.md | 0 .../src/config.rs | 0 .../src/error.rs | 6 +- {actix-staticfiles => actix-files}/src/lib.rs | 64 +++++++++--------- .../src/named.rs | 0 .../src/range.rs | 0 .../tests/test space.binary | 0 .../tests/test.binary | 0 .../tests/test.png | Bin 12 files changed, 37 insertions(+), 37 deletions(-) rename {actix-staticfiles => actix-files}/CHANGES.md (100%) rename {actix-staticfiles => actix-files}/Cargo.toml (97%) rename {actix-staticfiles => actix-files}/README.md (100%) rename {actix-staticfiles => actix-files}/src/config.rs (100%) rename {actix-staticfiles => actix-files}/src/error.rs (91%) rename {actix-staticfiles => actix-files}/src/lib.rs (94%) rename {actix-staticfiles => actix-files}/src/named.rs (100%) rename {actix-staticfiles => actix-files}/src/range.rs (100%) rename {actix-staticfiles => actix-files}/tests/test space.binary (100%) rename {actix-staticfiles => actix-files}/tests/test.binary (100%) rename {actix-staticfiles => actix-files}/tests/test.png (100%) diff --git a/Cargo.toml b/Cargo.toml index 2abb4c72..7b2e6c99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,8 @@ path = "src/lib.rs" [workspace] members = [ ".", + "actix-files", "actix-session", - "actix-staticfiles", ] [package.metadata.docs.rs] diff --git a/actix-staticfiles/CHANGES.md b/actix-files/CHANGES.md similarity index 100% rename from actix-staticfiles/CHANGES.md rename to actix-files/CHANGES.md diff --git a/actix-staticfiles/Cargo.toml b/actix-files/Cargo.toml similarity index 97% rename from actix-staticfiles/Cargo.toml rename to actix-files/Cargo.toml index 0a551792..7082d167 100644 --- a/actix-staticfiles/Cargo.toml +++ b/actix-files/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "actix-staticfiles" +name = "actix-files" version = "0.1.0" authors = ["Nikolay Kim "] description = "Static files support for Actix web." diff --git a/actix-staticfiles/README.md b/actix-files/README.md similarity index 100% rename from actix-staticfiles/README.md rename to actix-files/README.md diff --git a/actix-staticfiles/src/config.rs b/actix-files/src/config.rs similarity index 100% rename from actix-staticfiles/src/config.rs rename to actix-files/src/config.rs diff --git a/actix-staticfiles/src/error.rs b/actix-files/src/error.rs similarity index 91% rename from actix-staticfiles/src/error.rs rename to actix-files/src/error.rs index f165a618..ca99fa81 100644 --- a/actix-staticfiles/src/error.rs +++ b/actix-files/src/error.rs @@ -3,7 +3,7 @@ use derive_more::Display; /// Errors which can occur when serving static files. #[derive(Display, Debug, PartialEq)] -pub enum StaticFilesError { +pub enum FilesError { /// Path is not a directory #[display(fmt = "Path is not a directory. Unable to serve static files")] IsNotDirectory, @@ -13,8 +13,8 @@ pub enum StaticFilesError { IsDirectory, } -/// Return `NotFound` for `StaticFilesError` -impl ResponseError for StaticFilesError { +/// Return `NotFound` for `FilesError` +impl ResponseError for FilesError { fn error_response(&self) -> HttpResponse { HttpResponse::new(StatusCode::NOT_FOUND) } diff --git a/actix-staticfiles/src/lib.rs b/actix-files/src/lib.rs similarity index 94% rename from actix-staticfiles/src/lib.rs rename to actix-files/src/lib.rs index 7c3f6849..c6b52f04 100644 --- a/actix-staticfiles/src/lib.rs +++ b/actix-files/src/lib.rs @@ -29,7 +29,7 @@ mod error; mod named; mod range; -use self::error::{StaticFilesError, UriSegmentError}; +use self::error::{FilesError, UriSegmentError}; pub use crate::config::{DefaultConfig, StaticFileConfig}; pub use crate::named::NamedFile; pub use crate::range::HttpRange; @@ -222,10 +222,10 @@ fn directory_listing( /// /// fn main() { /// let app = App::new() -/// .service(fs::StaticFiles::new("/static", ".")); +/// .service(fs::Files::new("/static", ".")); /// } /// ``` -pub struct StaticFiles { +pub struct Files { path: String, directory: PathBuf, index: Option, @@ -237,28 +237,28 @@ pub struct StaticFiles { _cd_map: PhantomData, } -impl StaticFiles { - /// Create new `StaticFiles` instance for specified base directory. +impl Files { + /// Create new `Files` instance for specified base directory. /// /// `StaticFile` uses `ThreadPool` for blocking filesystem operations. /// By default pool with 5x threads of available cpus is used. /// Pool size can be changed by setting ACTIX_CPU_POOL environment variable. - pub fn new>(path: &str, dir: T) -> StaticFiles { + pub fn new>(path: &str, dir: T) -> Files { Self::with_config(path, dir, DefaultConfig) } } -impl StaticFiles { - /// Create new `StaticFiles` instance for specified base directory. +impl Files { + /// Create new `Files` instance for specified base directory. /// /// Identical with `new` but allows to specify configiration to use. - pub fn with_config>(path: &str, dir: T, _: C) -> StaticFiles { + pub fn with_config>(path: &str, dir: T, _: C) -> Files { let dir = dir.into().canonicalize().unwrap_or_else(|_| PathBuf::new()); if !dir.is_dir() { log::error!("Specified path is not a directory"); } - StaticFiles { + Files { path: path.to_string(), directory: dir, index: None, @@ -294,13 +294,13 @@ impl StaticFiles { /// /// Shows specific index file for directory "/" instead of /// showing files listing. - pub fn index_file>(mut self, index: T) -> StaticFiles { + pub fn index_file>(mut self, index: T) -> Files { self.index = Some(index.into()); self } } -impl HttpServiceFactory

for StaticFiles +impl HttpServiceFactory

for Files where P: 'static, C: StaticFileConfig + 'static, @@ -319,16 +319,16 @@ where } impl NewService> - for StaticFiles + for Files { type Response = ServiceResponse; type Error = (); - type Service = StaticFilesService; + type Service = FilesService; type InitError = (); type Future = FutureResult; fn new_service(&self, _: &()) -> Self::Future { - ok(StaticFilesService { + ok(FilesService { directory: self.directory.clone(), index: self.index.clone(), show_index: self.show_index, @@ -341,7 +341,7 @@ impl NewService> } } -pub struct StaticFilesService { +pub struct FilesService { directory: PathBuf, index: Option, show_index: bool, @@ -352,7 +352,7 @@ pub struct StaticFilesService { _cd_map: PhantomData, } -impl Service> for StaticFilesService { +impl Service> for FilesService { type Response = ServiceResponse; type Error = (); type Future = FutureResult; @@ -395,7 +395,7 @@ impl Service> for StaticFilesService

= StaticFiles::new("/", "missing"); - let _st: StaticFiles<()> = StaticFiles::new("/", "Cargo.toml"); + let _st: Files<()> = Files::new("/", "missing"); + let _st: Files<()> = Files::new("/", "Cargo.toml"); } // #[test] // fn test_default_handler_file_missing() { - // let st = StaticFiles::new(".") + // let st = Files::new(".") // .default_handler(|_: &_| "default content"); // let req = TestRequest::with_uri("/missing") // .param("tail", "missing") @@ -982,7 +982,7 @@ mod tests { // #[test] // fn test_serve_index() { - // let st = StaticFiles::new(".").index_file("test.binary"); + // let st = Files::new(".").index_file("test.binary"); // let req = TestRequest::default().uri("/tests").finish(); // let resp = st.handle(&req).respond_to(&req).unwrap(); @@ -1028,7 +1028,7 @@ mod tests { // #[test] // fn test_serve_index_nested() { - // let st = StaticFiles::new(".").index_file("mod.rs"); + // let st = Files::new(".").index_file("mod.rs"); // let req = TestRequest::default().uri("/src/client").finish(); // let resp = st.handle(&req).respond_to(&req).unwrap(); // let resp = resp.as_msg(); @@ -1048,7 +1048,7 @@ mod tests { // let mut srv = test::TestServer::with_factory(|| { // App::new().handler( // "test", - // StaticFiles::new(".").index_file("Cargo.toml"), + // Files::new(".").index_file("Cargo.toml"), // ) // }); @@ -1081,7 +1081,7 @@ mod tests { // let mut srv = test::TestServer::with_factory(|| { // App::new().handler( // "test", - // StaticFiles::new(".").index_file("Cargo.toml"), + // Files::new(".").index_file("Cargo.toml"), // ) // }); diff --git a/actix-staticfiles/src/named.rs b/actix-files/src/named.rs similarity index 100% rename from actix-staticfiles/src/named.rs rename to actix-files/src/named.rs diff --git a/actix-staticfiles/src/range.rs b/actix-files/src/range.rs similarity index 100% rename from actix-staticfiles/src/range.rs rename to actix-files/src/range.rs diff --git a/actix-staticfiles/tests/test space.binary b/actix-files/tests/test space.binary similarity index 100% rename from actix-staticfiles/tests/test space.binary rename to actix-files/tests/test space.binary diff --git a/actix-staticfiles/tests/test.binary b/actix-files/tests/test.binary similarity index 100% rename from actix-staticfiles/tests/test.binary rename to actix-files/tests/test.binary diff --git a/actix-staticfiles/tests/test.png b/actix-files/tests/test.png similarity index 100% rename from actix-staticfiles/tests/test.png rename to actix-files/tests/test.png