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. 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>

Source

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

Source

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.


  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 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.