#static #files #tide


A simple static file serving component for Rust’s Tide web framework

4 releases (stable)

✓ Uses Rust 2018 edition

new 2.0.1 Dec 12, 2019
2.0.0 Dec 10, 2019
1.0.0 Dec 2, 2019
0.1.0 Nov 30, 2019

#76 in HTTP server

25 downloads per month
Used in 1 crate


84 lines


A simple static file serving component for Rust's Tide web framework.


This code is based heavily on this archived example.


To use the library:

  1. Define some state for your server.
  2. Implement StaticRootDir on your state. This tells the library how to access the name of the root directory in which your static assets live.
  3. Set up a get endpoint with a *path glob pattern (like /static/*path or /*path) and have it call the serve_static_files function.
use std::path::{Path, PathBuf};
use tide_naive_static_files::{serve_static_files, StaticRootDir};

struct AppState { // 1.
    static_root_dir: PathBuf,

impl StaticRootDir for AppState { // 2.
    fn root_dir(&self) -> &Path {

async fn main() {
    let state = AppState {
        static_root_dir: "./examples/".into(),

    let mut app = tide::with_state(state);
    app.at("/static/*path") // 3.
        .get(|req| async { serve_static_files(req).await.unwrap() });


Too many task::block_ons

Right now it kinda doesn't use all the async-y-ness that it probably could. There are a couple of unfortunate task::block_ons that I want to get rid of. Suggestions welcome!


~147K SLoC