Skip to main content

Materializer

Struct Materializer 

Source
pub struct Materializer { /* private fields */ }
Expand description

Materializes git stubs into actual file content.

Reads .gitstub files, fetches the referenced content from Git history, and writes the content to an output directory.

Implementations§

Source§

impl Materializer

Source

pub fn standard( repo_root: impl Into<Utf8PathBuf>, output_dir: impl Into<Utf8PathBuf>, ) -> Result<Self, MaterializeError>

Creates a new materializer for general use.

repo_root must be the repository root, and it is treated as relative to the current working directory. (It is also allowed to be absolute.)

output_dir is an output directory relative to the current working directory. (It is also allowed to be absolute.)

Returns an error if no VCS (.git or .jj) is detected at repo_root, or if the repository is a shallow clone.

Source

pub fn for_build_script( repo_root: impl Into<Utf8PathBuf>, ) -> Result<Self, MaterializeError>

Creates a new materializer for use in Cargo build scripts.

This constructor reads OUT_DIR from the environment for the output directory, and writes files to the git-stub-vcs directory within OUT_DIR. It also emits cargo::rerun-if-changed directives for each materialized file.

repo_root is relative to CARGO_MANIFEST_DIR (the directory containing the crate’s Cargo.toml), and is typically a relative path.

§Panics

Panics if the OUT_DIR or CARGO_MANIFEST_DIR environment variables are not set. Both these environment variables are expected to be set in a Cargo build script context.

Source

pub fn with_vcs(self, vcs: Vcs) -> Result<Self, MaterializeError>

Overrides the detected VCS.

Use this when you want to force a specific VCS instead of relying on automatic detection.

Returns an error if shallow-clone checking fails, or if the repository is shallow under the new VCS.

Source

pub fn vcs(&self) -> &Vcs

Returns the VCS that will be used for materialization.

Source

pub fn materialize( &self, git_stub_path: impl AsRef<Utf8Path>, ) -> Result<Utf8PathBuf, MaterializeError>

Materializes a git stub.

Reads the file at git_stub_path (relative to the repository root), fetches the referenced content from history, and writes it to the output directory.

Returns the path to the materialized file.

§Examples
// In build.rs:
let materializer = git_stub_vcs::Materializer::for_build_script("../..")
    .expect("VCS detected at repo root");
let spec_path = materializer
    .materialize("openapi/my-api/my-api-1.0.0-abc123.json.gitstub")
    .expect("materialized successfully");
Source

pub fn materialize_to( &self, git_stub_path: impl AsRef<Utf8Path>, output_path: impl AsRef<Utf8Path>, ) -> Result<(), MaterializeError>

Materializes a git stub to a specific path.

Like materialize, but writes to output_path (relative to the output directory, or absolute) instead of deriving the path from the Git stub file name.

git_stub_path is relative to the repository root.

Trait Implementations§

Source§

impl Clone for Materializer

Source§

fn clone(&self) -> Materializer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Materializer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.