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.
Sourcepub fn map_well_known_types(self: Pin<&mut Self>)
pub fn map_well_known_types(self: Pin<&mut Self>)
Maps the well-known protobuf types to the source tree.
This method makes the well-known types (like google/protobuf/any.proto,
google/protobuf/timestamp.proto, etc.) available for import.
The proto files are embedded at compile time, so this method works even if the protobuf include directory is not available at runtime.
§Note
This method writes the embedded proto files to a temporary directory
on disk (under $TMPDIR/protobuf-native-well-known-types-{version}/)
on first invocation. The directory persists for the lifetime of the
process and across invocations. If you need to avoid disk writes,
consider using VirtualSourceTree::map_well_known_types instead.
§Example
use std::path::Path;
use protobuf_native::compiler::DiskSourceTree;
let mut source_tree = DiskSourceTree::new();
source_tree.as_mut().map_well_known_types();
source_tree.as_mut().map_path(Path::new(""), Path::new("my/protos"));
// Now you can import well-known types in your .proto files:
// import "google/protobuf/timestamp.proto";