Struct protobuf_native::compiler::DiskSourceTree
source · pub struct DiskSourceTree { /* private fields */ }
Expand description
An implementation of SourceTree
which loads files from locations on disk.
Multiple mappings can be set up to map locations in the DiskSourceTree
to
locations in the physical filesystem.
Implementations§
source§impl DiskSourceTree
impl DiskSourceTree
sourcepub fn new() -> Pin<Box<DiskSourceTree>>
pub fn new() -> Pin<Box<DiskSourceTree>>
Creates a new disk source tree.
sourcepub fn map_path(self: Pin<&mut Self>, virtual_path: &Path, disk_path: &Path)
pub fn map_path(self: Pin<&mut Self>, virtual_path: &Path, disk_path: &Path)
Maps a path on disk to a location in the source tree.
The path may be either a file or a directory. If it is a directory, the
entire tree under it will be mapped to the given virtual location. To
map a directory to the root of the source tree, pass an empty string for
virtual_path
.
If multiple mapped paths apply when opening a file, they will be searched in order. For example, if you do:
use std::path::Path;
use protobuf_native::compiler::DiskSourceTree;
let mut source_tree = DiskSourceTree::new();
source_tree.as_mut().map_path(Path::new("bar"), Path::new("foo/bar"));
source_tree.as_mut().map_path(Path::new(""), Path::new("baz"));
and then you do:
source_tree.open(Path::new("bar/qux"));
the DiskSourceTree
will first try to open foo/bar/qux, then
baz/bar/qux, returning the first one that opens successfully.
disk_path
may be an absolute path or relative to the current directory,
just like a path you’d pass to File::open
.