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. Transformations like
inline_tagged_variants 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>
pub fn new(arena: &'a Arena, spec: &'a Spec<'a>) -> Self
Sourcepub fn inline_tagged_variants(&mut self) -> &mut Self
pub fn inline_tagged_variants(&mut self) -> &mut Self
Inlines schema types used as variants of multiple tagged unions with different tags.
In OpenAPI’s model of tagged unions, the tag always references a field that’s defined on each struct variant. This model works well for Python and TypeScript, but not Rust; Serde doesn’t allow struct variants 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 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 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> 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> 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
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