pub struct Stager { /* private fields */ }Expand description
Accumulates (relative_path, bytes) pairs and writes them to a
fresh tempdir laid out as <tmp>/<relative_path>.
relative_path is the protoc-style import path the consuming
.proto will use (bones/v1/pagination.proto, etc.). The
returned tempfile::TempDir cleans up on drop — hold it until
codegen finishes.
§Examples
use proto_build_kit::Stager;
const FOO: &[u8] = b"syntax = \"proto3\"; package foo.v1; message Foo {}";
fn build() -> Result<(), Box<dyn std::error::Error>> {
let staged = Stager::new()
.add("foo/v1/foo.proto", FOO)
.stage()?;
// Use staged.path() on your protoc include path.
Ok(())
}Pair with a sibling *-protos crate that exposes files():
let staged = Stager::new()
.with(some_protos::files())
.with(other_protos::files())
.stage()?;§Duplicate detection
Two entries with the same relative_path cause stage() to return
Error::DuplicatePath. This protects against silent shadowing when
two *-protos crates collide on a path — almost always a bug.
Implementations§
Source§impl Stager
impl Stager
Sourcepub fn add(self, relative_path: &'static str, bytes: &'static [u8]) -> Self
pub fn add(self, relative_path: &'static str, bytes: &'static [u8]) -> Self
Append a single (relative_path, bytes) entry.
Sourcepub fn with<I>(self, iter: I) -> Self
pub fn with<I>(self, iter: I) -> Self
Append every entry yielded by iter. Typically called with a
*-protos crate’s files() accessor.
Sourcepub fn stage(self) -> Result<TempDir, Error>
pub fn stage(self) -> Result<TempDir, Error>
Write every staged entry to a fresh tempdir and return the
handle. Add tempdir.path() to your protoc include path.
§Errors
Error::DuplicatePathif two entries declare the same relative path.Error::Ioif tempdir creation, directory creation, or file writes fail.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Stager
impl RefUnwindSafe for Stager
impl Send for Stager
impl Sync for Stager
impl Unpin for Stager
impl UnsafeUnpin for Stager
impl UnwindSafe for Stager
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more