qrock 0.2.2

Helpers for Rocket HTTP server applications.
Documentation
//! Static content.

pub mod bisc;

use std::path::Path;

use rocket::fs::FileServer;

/// Set up a series of physical directories to be mounted at a single
/// location.
///
/// The directories should be listed in search order (i.e. the first entry will
/// be checked first, and the last will be checked last).
///
///```
/// use qrock::sc::setup_static_dirs;
///
/// let rocket = rocket::build();
///
/// let dirs = ["/tmp"];
/// let rocket = setup_static_dirs(rocket, "/static", dirs.iter());
/// ```
#[allow(clippy::cast_possible_wrap)]
pub fn setup_static_dirs<I, P>(
  mut rocket: rocket::Rocket<rocket::Build>,
  mnt: &str,
  dirs: I
) -> rocket::Rocket<rocket::Build>
where
  I: Iterator<Item = P>,
  P: AsRef<Path>
{
  let dirs = dirs.enumerate();
  for (idx, dir) in dirs {
    // clippy warns about a potential integer wrap-around here.
    // The warning is disabled since it's not considered to be a practical
    // problem.
    rocket = rocket.mount(mnt, FileServer::from(dir).rank(idx as isize));
  }
  rocket
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :