pub struct TypeNames { /* private fields */ }Expand description
The final Rust type name of every top-level schema, together with each collision that still needs a decision from the author.
A collision is not an error at resolution time. Default pruning drops a schema
that no generated operation uses, and two dropped schemas that collapse onto
one Rust identifier cause no problem in the output. The caller therefore holds
this value until the module is final and then calls TypeNames::check_emitted.
Implementations§
Source§impl TypeNames
impl TypeNames
Sourcepub fn renames(&self) -> &HashMap<String, String>
pub fn renames(&self) -> &HashMap<String, String>
The renames to apply to every Named reference and item name.
The map holds one entry for each top-level schema whose emitted name
differs from the plain to_ident(name). Two sources add an entry:
- an
x-rust-nameoverride (inline schemas only), and - a collision suffix from
output-options.type-name-suffix, added to the second of two schema names that collapse onto one Rust identifier.
The map omits a schema whose emitted name does not change. The common case therefore gives an empty map, and the rewrite passes do no work.
An unresolved collision adds no entry, so both schemas keep the plain name. The module then holds two items with that one name, which is why an unchecked collision must never reach the emitter.
Sourcepub fn check_emitted(&self, module: &Module) -> Result<()>
pub fn check_emitted(&self, module: &Module) -> Result<()>
Report a collision whose Rust type name module still holds, and collect
every such collision into one result.
The emitted name is what decides. Two items with one name do not compile,
whatever schema each item came from, and a schema that module does not
hold emits no item at all. The check is therefore keyed on the identifier
and not on the provenance of the two schemas.
Keying on the identifier also covers a name that a hoisted inline type
takes. Pruning is name-based (see crate::lower::prune), so an inline
item named FooBar keeps two unused foo-bar and fooBar components
alive. Three items then share one name. The collision is real there, even
though no operation reaches either component.
A caller that prunes nothing gets a module that holds every schema, so every collision reports.
§Errors
Returns one Error::SchemaNameCollision for a single surviving
collision, or an Error::Validation that holds all of them.