Skip to main content

generate_with_diagnostics

Function generate_with_diagnostics 

Source
pub fn generate_with_diagnostics(
    file_descriptors: &[FileDescriptorProto],
    files_to_generate: &[String],
    config: &CodeGenConfig,
) -> Result<(Vec<GeneratedFile>, Vec<CodeGenWarning>), CodeGenError>
Expand description

Like generate, but also returns the non-fatal CodeGenWarnings collected during generation (e.g. enums whose idiomatic CamelCase aliases were suppressed by a naming conflict).

Surface each warning via its Display impl — e.g. as a cargo:warning=... from a build.rs, or on stderr from a standalone generator — or match on it for programmatic handling. generate discards them, so existing callers are unaffected.

Warnings are returned only on success. On error, any warnings already collected are dropped along with the partial output — the CodeGenError is the actionable signal.

§Errors

Returns CodeGenError::FileNotFound if a name in files_to_generate has no matching descriptor, CodeGenError::Other if generate_reflection_vtable is set without generate_reflection, and other CodeGenError variants for malformed descriptors (e.g. a missing required field) encountered while generating.