Skip to main content

TypeNames

Struct TypeNames 

Source
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

Source

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-name override (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.

Source

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.

Trait Implementations§

Source§

impl Debug for TypeNames

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.