Struct Generator

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

Configurable Rust code generator for schema-derived type information.

The Generator type provides a flexible interface to customize how Rust code structures are generated from XSD-like schema models represented as MetaTypes. It supports configuration of type postfixes, boxing rules, serde integration, and more.

Once all configuration is applied, the generator can be “sealed” into a GeneratorFixed instance using into_fixed, after which only code generation (not configuration) is permitted.

Implementations§

Source§

impl<'types> Generator<'types>

Source

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

Create a new code generator from the passed types.

Source

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

Set the BoxFlags flags 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 flags(self, value: GeneratorFlags) -> Self

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

Source

pub fn any_type<P>(self, path: P) -> Result<Self, P::Error>
where P: TryInto<IdentPath>,

Set the type to use to store unstructured xs:any elements.

If this is set, the generator will create additional fields to store unstructured XML data for elements that has xs:any set.

§Errors

Forwards the error that is thrown, if path could not be converted.

Source

pub fn any_attribute_type<P>(self, path: P) -> Result<Self, P::Error>
where P: TryInto<IdentPath>,

Set the type to use to store unstructured xs:anyAttribute attributes.

If this is set, the generator will create additional fields to store unstructured XML attributes for elements that has xs:anyAttribute set.

§Errors

Forwards the error that is thrown, if path could not be converted.

Source

pub fn with_flags(self, value: GeneratorFlags) -> Self

Add the passed GeneratorFlags 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<GeneratorFixed<'types>, Error>

Will fix the generator by call into_fixed and then generate_type.

Source

pub fn generate_named_types(self) -> Result<GeneratorFixed<'types>, Error>

Will fix the generator by call into_fixed and then generate_named_types.

§Errors

Will just forward the errors from generate_named_types.

Source

pub fn generate_all_types(self) -> Result<GeneratorFixed<'types>, Error>

Will fix the generator by call into_fixed and then generate_all_types.

§Errors

Will just forward the errors from generate_all_types.

Source

pub fn into_fixed(self) -> GeneratorFixed<'types>

Will convert the generator into a GeneratorFixed.

You need to call this method if the general configuration of the generator is finished. The resulting GeneratorFixed type will only provide methods to generate data types for specific types. The underlying configuration can not be changed anymore.

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<X> AsAny for X
where X: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get a reference to the current object as Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get a mutable reference to the current object as Any.
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