Skip to main content

Stager

Struct Stager 

Source
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

Source

pub fn new() -> Self

Construct an empty stager.

Source

pub fn add(self, relative_path: &'static str, bytes: &'static [u8]) -> Self

Append a single (relative_path, bytes) entry.

Source

pub fn with<I>(self, iter: I) -> Self
where I: IntoIterator<Item = (&'static str, &'static [u8])>,

Append every entry yielded by iter. Typically called with a *-protos crate’s files() accessor.

Source

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

Trait Implementations§

Source§

impl Default for Stager

Source§

fn default() -> Stager

Returns the “default value” for a type. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

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>,

Source§

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.