Skip to main content

file_uri_path

Function file_uri_path 

pub fn file_uri_path(uri: &Uri) -> Result<PathBuf, FileUriError>
Available on crate feature net only.
Expand description

The filesystem path a file: Uri refers to.

  • file:///etc/hosts/etc/hosts
  • file://localhost/etc/hosts/etc/hosts
  • file:///C:/Users/x (windows) → C:/Users/x
  • file://server/share/x (windows) → \\server\share\x

Per RFC 8089 §2 only an empty authority or localhost names this machine. Any other authority names a different host: on windows that is the UNC form of Appendix E.3.2 and maps to \\host\path, and everywhere else there is no such path, so it is refused rather than read from the local filesystem.

Percent-escapes are decoded per segment; a segment that decodes to a path separator is rejected rather than silently traversing. Callers should Uri::canonicalize first so ./.. are resolved, and open the result through rama_utils::fs rather than std::fs.