1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-12-18 01:43:58 +01:00

improve docs for Files::new

This commit is contained in:
Rob Ede 2020-11-24 20:23:09 +00:00
parent 5af46775b8
commit f1a9b45437
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
2 changed files with 23 additions and 7 deletions

View File

@ -3,6 +3,10 @@
## Unreleased - 2020-xx-xx ## Unreleased - 2020-xx-xx
## 0.4.1 - 2020-11-24
* Clarify order of parameters in `Files::new` and improve docs.
## 0.4.0 - 2020-10-06 ## 0.4.0 - 2020-10-06
* Add `Files::prefer_utf8` option that adds UTF-8 charset on certain response types. [#1714] * Add `Files::prefer_utf8` option that adds UTF-8 charset on certain response types. [#1714]

View File

@ -65,13 +65,25 @@ impl Clone for Files {
} }
impl Files { impl Files {
/// Create new `Files` instance for specified base directory. /// Create new `Files` instance for a specified base directory.
/// ///
/// `File` uses `ThreadPool` for blocking filesystem operations. /// # Argument Order
/// By default pool with 5x threads of available cpus is used. /// The first argument (`mount_path`) is the root URL at which the static files are served.
/// Pool size can be changed by setting ACTIX_THREADPOOL environment variable. /// For example, `/assets` will serve files at `example.com/assets/...`.
pub fn new<T: Into<PathBuf>>(path: &str, dir: T) -> Files { ///
let orig_dir = dir.into(); /// The second argument (`serve_from`) is the location on disk at which files are loaded.
/// This can be a relative path. For example, `./` would serve files from the current
/// working directory.
///
/// # Implementation Notes
/// If the mount path is set as the root path `/`, services registered after this one will
/// be inaccessible. Register more specific handlers and services first.
///
/// `Files` uses a threadpool for blocking filesystem operations. By default, the pool uses a
/// number of threads equal to 5x the number of available logical CPUs. Pool size can be changed
/// by setting ACTIX_THREADPOOL environment variable.
pub fn new<T: Into<PathBuf>>(mount_path: &str, serve_from: T) -> Files {
let orig_dir = serve_from.into();
let dir = match orig_dir.canonicalize() { let dir = match orig_dir.canonicalize() {
Ok(canon_dir) => canon_dir, Ok(canon_dir) => canon_dir,
Err(_) => { Err(_) => {
@ -81,7 +93,7 @@ impl Files {
}; };
Files { Files {
path: path.to_string(), path: mount_path.to_owned(),
directory: dir, directory: dir,
index: None, index: None,
show_index: false, show_index: false,