Skip to main content

trillium_static/
resolved_directory.rs

1use std::path::{Path, PathBuf};
2
3/// A directory that [`StaticFileHandler`][crate::StaticFileHandler] resolved
4/// from the request path but did not serve a file from — either because no
5/// index file is configured or because the configured index was absent.
6///
7/// When this happens, the handler leaves the conn unhalted and stores the
8/// resolved directory in conn state rather than serving it, so a subsequent
9/// handler can enumerate the directory and render a listing. The contained
10/// path has already passed the handler's traversal-containment check, so it is
11/// guaranteed to be within the served root.
12///
13/// Retrieve it with
14/// [`StaticConnExt::resolved_directory`][crate::StaticConnExt::resolved_directory].
15#[derive(Debug, Clone)]
16pub struct ResolvedDirectory(PathBuf);
17
18impl ResolvedDirectory {
19    pub(crate) const fn new(path: PathBuf) -> Self {
20        Self(path)
21    }
22
23    /// The resolved filesystem path of the directory.
24    #[must_use]
25    pub fn path(&self) -> &Path {
26        &self.0
27    }
28}