Skip to main content

RawGraph

Struct RawGraph 

Source
pub struct RawGraph<'a> { /* private fields */ }
Expand description

A mutable intermediate dependency graph of all the types in a Spec, backed by a sparse StableDiGraph.

This graph is constructed directly from a Spec, and represents type relationships as they exist in the spec. Transformation methods rewrite this graph in place.

After applying all transformations, call cook to turn this graph into a CookedGraph that’s ready for code generation.

Implementations§

Source§

impl<'a> RawGraph<'a>

Source

pub fn new(arena: &'a Arena, spec: &'a Spec<'a>) -> Self

Builds a raw type graph from the given spec.

Source

pub fn inline_tagged_variants(&mut self) -> &mut Self

Inlines struct variants that are variants of multiple tagged unions with different tags, or that inherit their tagged union’s own fields.

In OpenAPI’s model of tagged unions, the tag always references a field that’s defined on each variant struct. This model works well for Python and TypeScript, but not Rust; Serde doesn’t allow variant structs to declare fields with the same name as the tag. The Rust generator excludes tag fields when generating structs, but this introduces a new problem: a struct can’t appear as a variant of multiple unions with different tags 1.

This transformation finds and inlines these structs, so that the Rust generator can safely omit their tag fields.


  1. If struct A has fields foo and bar, A is a variant of tagged unions C and D, C’s tag is foo, and D’s tag is bar… only foo should be excluded when A is used in C, and only bar should be excluded when A is used in D; but this can’t be modeled in Serde without splitting A into two distinct types. 

Source

pub fn inline_untagged_variants(&mut self) -> &mut Self

Inlines struct variants of untagged unions where the union declares own properties, but the struct doesn’t inherit them via allOf.

Source

pub fn collapse_trivial_inlines(&mut self) -> &mut Self

Simplifies trivial allOf compositions.

Drops inheritance edges from Any, and collapses inline structs and unions with a single parent and without own fields or variants, to that parent. Trivial named schemas are preserved, so that user code can refer to them by name.

This transformation simplifies OpenAPI 3.1 $ref schemas with adjacent keywords. A schema like { "$ref": "...", "description": "..." } is sugar for an inline allOf schema with two subschemas: a reference and an inline with just a description. The latter doesn’t contribute any type constraints, so the inline allOf is redundant.

Source

pub fn cook(&self) -> CookedGraph<'a>

Builds an immutable CookedGraph from this mutable raw graph.

Trait Implementations§

Source§

impl<'a> Debug for RawGraph<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RawGraph<'a>

§

impl<'a> !RefUnwindSafe for RawGraph<'a>

§

impl<'a> !Send for RawGraph<'a>

§

impl<'a> !Sync for RawGraph<'a>

§

impl<'a> Unpin for RawGraph<'a>

§

impl<'a> UnsafeUnpin for RawGraph<'a>

§

impl<'a> !UnwindSafe for RawGraph<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.