pub struct Committed { /* private fields */ }Expand description
The files a generator writes, and the command that regenerates them.
update writes the files. check compares them with disk.
use layline_codegen::emit::{Committed, Module, generate};
/// Regenerates the artifact.
const COMMAND: &str = "cargo codegen";
fn committed() -> Committed {
let module = Module::new(vec![]).with_doc(vec![format!("Regenerate with `{COMMAND}`.")]);
Committed::by(COMMAND).file("src/generated/wire.rs", generate(&module).unwrap().source)
}
fn main() {
for change in committed().update().expect("write the artifact") {
println!("{change}");
}
}
#[test]
fn the_committed_source_is_what_the_emitter_writes() {
committed().check().expect("the committed artifact is current");
}Implementations§
Source§impl Committed
impl Committed
Sourcepub fn by(command: impl Into<String>) -> Self
pub fn by(command: impl Into<String>) -> Self
An empty set of files, regenerated by command.
Failures quote command, so it should run from the repository root.
Sourcepub fn file(self, path: impl Into<PathBuf>, contents: impl Into<String>) -> Self
pub fn file(self, path: impl Into<PathBuf>, contents: impl Into<String>) -> Self
Adds a file. A later call for the same path replaces it.
Sourcepub fn dir<N, C>(
self,
dir: impl Into<PathBuf>,
files: impl IntoIterator<Item = (N, C)>,
) -> Self
pub fn dir<N, C>( self, dir: impl Into<PathBuf>, files: impl IntoIterator<Item = (N, C)>, ) -> Self
Adds a directory whose .rs files must be exactly files, as (name, contents) pairs.
Other .rs files in dir are reported and deleted. Everything else is left alone.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Committed
impl RefUnwindSafe for Committed
impl Send for Committed
impl Sync for Committed
impl Unpin for Committed
impl UnsafeUnpin for Committed
impl UnwindSafe for Committed
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