xsd_parser::generator

Struct Generator

Source
pub struct Generator<'types> { /* private fields */ }
Expand description

Type that is used to generate rust code from a Types object.

Implementations§

Source§

impl<'types> Generator<'types>

Source

pub fn new(types: &'types Types) -> Self

Create a new code generator from the passed types.

Source

pub fn xsd_parser_crate<S: Display>(self, value: S) -> Self

Set the name of the xsd-parser create that the generator should use for generating the code.

Source

pub fn derive<I>(self, value: I) -> Self
where I: IntoIterator, I::Item: Display,

Set the traits the generated types should derive from.

Default is Debug and Clone.

§Examples
let generator = Generator::new(types)
    .derive(vec!["Debug", "Clone", "Eq", "PartialEq", "Ord", "PartialOrd"]);
Source

pub fn box_flags(self, value: BoxFlags) -> Self

Set the BoxFlags flags the generator should use for generating the code.

Source

pub fn content_mode(self, value: ContentMode) -> Self

Set the ContentMode value the generator should use for generating the code.

Source

pub fn typedef_mode(self, value: TypedefMode) -> Self

Set the TypedefMode value the generator should use for generating the code.

Source

pub fn serde_support(self, value: SerdeSupport) -> Self

Set the SerdeSupport value the generator should use for generating the code.

Source

pub fn generate_flags(self, value: GenerateFlags) -> Self

Set the GenerateFlags flags the generator should use for generating the code.

Source

pub fn with_generate_flags(self, value: GenerateFlags) -> Self

Add the passed GenerateFlags flags the generator should use for generating the code.

Source

pub fn with_type_postfix<S: Into<String>>( self, type_: IdentType, postfix: S, ) -> Self

Set the postfixes the generator should use for the different types.

Default is "Type" for the IdentType::Type type and "" for the other types.

Source

pub fn with_type(self, ident: Ident) -> Result<Self, Error>

Add a custom implemented type to the generator.

This will add a custom implemented type to the generator. These types are usually implemented and provided by the user of the generated code. The generator will just reference to the type definition and will not generate any code related to this type.

§Errors

Returns an error if the namespace of the passed identifier is unknown.

§Examples
let generator = Generator::new(types)
    .with_type(Ident::type_("UserDefinedType"));
Source

pub fn generate_type(self, ident: Ident) -> Result<Self, Error>

Generate the code for the given type.

This will generate the code for the passed type identifier and all dependencies of this type.

§Examples
let generator = Generator::new(types)
    .generate_type(Ident::type_("Root"));
Source

pub fn generate_all_types(self) -> Result<Self, Error>

Generate the code for all types.

This will generate the code for all types and all dependencies of this type that are specified in the Types object passed to the generator.

§Examples
let generator = Generator::new(types)
    .generate_all_types();
Source

pub fn finish(self) -> TokenStream

Finish the code generation.

THis will return the generated code as TokenStream.

Trait Implementations§

Source§

impl<'types> Debug for Generator<'types>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'types> Freeze for Generator<'types>

§

impl<'types> !RefUnwindSafe for Generator<'types>

§

impl<'types> !Send for Generator<'types>

§

impl<'types> !Sync for Generator<'types>

§

impl<'types> Unpin for Generator<'types>

§

impl<'types> !UnwindSafe for Generator<'types>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T