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

source

pub fn new() -> Pin<Box<DiskSourceTree>>

Creates a new disk source tree.

source

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.

Trait Implementations§

source§

impl Drop for DiskSourceTree

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl SourceTree for DiskSourceTree

source§

fn open<'a>( self: Pin<&'a mut Self>, filename: &Path ) -> Result<Pin<Box<DynZeroCopyInputStream<'a>>>, FileOpenError>

Opens the given file and return a stream that reads it. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.