1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-10 17:29:36 +00: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
## 0.4.1 - 2020-11-24
* Clarify order of parameters in `Files::new` and improve docs.
## 0.4.0 - 2020-10-06
* 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 {
/// Create new `Files` instance for specified base directory.
/// Create new `Files` instance for a specified base directory.
///
/// `File` 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_THREADPOOL environment variable.
pub fn new<T: Into<PathBuf>>(path: &str, dir: T) -> Files {
let orig_dir = dir.into();
/// # Argument Order
/// The first argument (`mount_path`) is the root URL at which the static files are served.
/// For example, `/assets` will serve files at `example.com/assets/...`.
///
/// 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() {
Ok(canon_dir) => canon_dir,
Err(_) => {
@ -81,7 +93,7 @@ impl Files {
};
Files {
path: path.to_string(),
path: mount_path.to_owned(),
directory: dir,
index: None,
show_index: false,