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).
Report each warning through 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.
A name listed twice in files_to_generate is generated once.
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
CodeGenError::FileNotFoundif a name infiles_to_generatehas no matching descriptor.CodeGenError::OutputFileNameConflictif two generated files would be written to the same output path.CodeGenError::InvalidTypeNamePrefixifCodeGenConfig::type_name_prefixis neither empty nor PascalCase.CodeGenError::InvalidCustomAttributeif a custom attribute string, such as one inCodeGenConfig::type_attributes, is not one or more outer#[...]attributes.CodeGenError::Otherifconfigsets an option without the option it requires:generate_reflection_vtableorshared_descriptor_poolwithoutgenerate_reflection,shared_descriptor_pool_rootwithoutshared_descriptor_pool, oridiomatic_importswithoutfile_per_package.CodeGenError::Otherif an active feature-gate name inCodeGenConfig::feature_gate_namesis not a valid Cargo feature name, or ifshared_descriptor_pool_rootor anexclude_packagesentry is malformed.CodeGenError::SharedCorpusContextMismatchifCodeGenConfig::shared_corpus_contextwas built from a different corpus or different rules than this call uses.- For a valid schema whose names collide in the generated Rust:
CodeGenError::OneofEnumNameConflict,CodeGenError::OneofVariantNameConflict,CodeGenError::TypeNameConflict,CodeGenError::ModuleNameConflict,CodeGenError::ReservedFieldNameorCodeGenError::ReservedModuleName. CodeGenError::DuplicateFieldNumberif a message of a file infiles_to_generatehas two fields with one field number, which protoc rejects.- Other
CodeGenErrorvariants for a schema that generation does not support or a malformed descriptor, such asCodeGenError::MissingField.