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>
impl<'a> RawGraph<'a>
Sourcepub fn new(arena: &'a Arena, spec: &'a Spec<'a>) -> Self
pub fn new(arena: &'a Arena, spec: &'a Spec<'a>) -> Self
Builds a raw type graph from the given spec.
Sourcepub fn inline_tagged_variants(&mut self) -> &mut Self
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.
If struct A has fields
fooandbar, A is a variant of tagged unions C and D, C’s tag isfoo, and D’s tag isbar… onlyfooshould be excluded when A is used in C, and onlybarshould be excluded when A is used in D; but this can’t be modeled in Serde without splitting A into two distinct types. ↩
Sourcepub fn inline_untagged_variants(&mut self) -> &mut Self
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.
Sourcepub fn collapse_trivial_inlines(&mut self) -> &mut Self
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.
Sourcepub fn cook(&self) -> CookedGraph<'a>
pub fn cook(&self) -> CookedGraph<'a>
Builds an immutable CookedGraph from this mutable raw graph.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for RawGraph<'a>
impl<'a> !Send for RawGraph<'a>
impl<'a> !Sync for RawGraph<'a>
impl<'a> !UnwindSafe for RawGraph<'a>
impl<'a> Freeze for RawGraph<'a>
impl<'a> Unpin for RawGraph<'a>
impl<'a> UnsafeUnpin for RawGraph<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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