Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem:
    Debug
    + Send
    + Sync {
    // Required method
    fn read(&self, path: &Path) -> Result<SourceBytes>;

    // Provided method
    fn identity(&self, path: &Path) -> PathBuf { ... }
}
Expand description

Where the compiler reads source from.

There is no exists, deliberately. Whether a file is there is answered by trying to read it, and an interface with a separate question invites the race where the answer changes between the two calls.

Required Methods§

Source

fn read(&self, path: &Path) -> Result<SourceBytes>

Reads a file.

§Errors

Whatever the underlying file system says. io::ErrorKind::NotFound is the ordinary case during an include search and is not by itself a problem.

Provided Methods§

Source

fn identity(&self, path: &Path) -> PathBuf

What this file system calls a file, for deciding that two names are one file.

The multiple include optimization has to answer whether a header has been read already, and the name in the directive is not that answer. One header found through -I . and found again through -I /tree arrives under two names, and a project with more than one include directory reaches the same header both ways all day. So does a file that includes itself, which is the whole point of #pragma once in a main file.

The default is path_key, the text with the . components taken out, which is all a map from name to bytes can say. An implementation backed by a real file system resolves the name instead, so that a symlink, a .. and a relative path all land on the same answer. Only called for a file that has already been read, so it is a question about a file that is there rather than a probe.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§