pub struct VirtualSourceTree { /* private fields */ }Expand description
An implementation of SourceTree which stores files in memory.
Implementations§
Source§impl VirtualSourceTree
impl VirtualSourceTree
Sourcepub fn new() -> Pin<Box<VirtualSourceTree>>
pub fn new() -> Pin<Box<VirtualSourceTree>>
Creates a new virtual source tree.
Sourcepub fn add_file(self: Pin<&mut Self>, filename: &Path, contents: Vec<u8>)
pub fn add_file(self: Pin<&mut Self>, filename: &Path, contents: Vec<u8>)
Adds a file to the source tree with the specified name and contents.
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 adds all well-known type .proto files (like
google/protobuf/any.proto, google/protobuf/timestamp.proto, etc.)
to the virtual source tree, making them 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.
§Example
use std::path::Path;
use protobuf_native::compiler::VirtualSourceTree;
let mut source_tree = VirtualSourceTree::new();
source_tree.as_mut().map_well_known_types();
source_tree.as_mut().add_file(
Path::new("my.proto"),
b"syntax = \"proto3\";\nimport \"google/protobuf/timestamp.proto\";\n".to_vec(),
);
// Now my.proto can import well-known typesTrait Implementations§
Source§impl Drop for VirtualSourceTree
impl Drop for VirtualSourceTree
Source§impl SourceTree for VirtualSourceTree
impl SourceTree for VirtualSourceTree
Auto Trait Implementations§
impl Freeze for VirtualSourceTree
impl RefUnwindSafe for VirtualSourceTree
impl Send for VirtualSourceTree
impl Sync for VirtualSourceTree
impl !Unpin for VirtualSourceTree
impl UnwindSafe for VirtualSourceTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more