pub struct SharedCorpusContext { /* private fields */ }Expand description
The corpus-wide state CodeGenContext derives on every generate()
call — which oneof variants are unboxed, which message fields are stored
inline, and the raw comment text per fully-qualified name — none of which
depends on the extern paths that legitimately vary per call in a
one-crate-per-package workspace. Build one with SharedCorpusContext::new
from the whole corpus and set CodeGenConfig::shared_corpus_context on
every per-package config to skip that work on each call.
A context is only valid for the exact files and the same
unboxed_oneof_fields/pointer_fields it was built from; generate
checks both and returns CodeGenError::SharedCorpusContextMismatch
rather than emitting code resolved against a different corpus. The
context holds the corpus comment map for as long as any clone of it lives,
so drop it once code generation is done. Cloning shares the precomputed
state (Arcs inside), and the type is Send + Sync, so one context can
be handed to parallel per-package generate() calls.
§Examples
use buffa_codegen::{CodeGenConfig, SharedCorpusContext};
let base = CodeGenConfig::default();
let shared = SharedCorpusContext::new(&corpus, &base);
for (extern_prefix, files_to_generate) in packages {
let mut config = base.clone();
config.extern_paths.push((extern_prefix, "::other_crate".to_string()));
config.shared_corpus_context = Some(shared.clone());
let _files = buffa_codegen::generate(&corpus, &files_to_generate, &config)?;
}Implementations§
Sourcepub fn new(files: &[FileDescriptorProto], config: &CodeGenConfig) -> Self
pub fn new(files: &[FileDescriptorProto], config: &CodeGenConfig) -> Self
Precompute the corpus-wide state for files under config’s oneof
and pointer-representation rules, for reuse across every generate()
call that passes the same files and rules (see
CodeGenConfig::shared_corpus_context).