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>
impl<'types> Generator<'types>
Sourcepub fn new(types: &'types MetaTypes) -> Self
pub fn new(types: &'types MetaTypes) -> Self
Create a new code generator from the passed types
.
Sourcepub fn box_flags(self, value: BoxFlags) -> Self
pub fn box_flags(self, value: BoxFlags) -> Self
Set the BoxFlags
flags the generator should use for generating the code.
Sourcepub fn typedef_mode(self, value: TypedefMode) -> Self
pub fn typedef_mode(self, value: TypedefMode) -> Self
Set the TypedefMode
value the generator should use for generating the code.
Sourcepub fn flags(self, value: GeneratorFlags) -> Self
pub fn flags(self, value: GeneratorFlags) -> Self
Set the GeneratorFlags
flags the generator should use for generating the code.
Sourcepub fn any_type<P>(self, path: P) -> Result<Self, P::Error>
pub fn any_type<P>(self, path: P) -> Result<Self, P::Error>
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.
Sourcepub fn any_attribute_type<P>(self, path: P) -> Result<Self, P::Error>
pub fn any_attribute_type<P>(self, path: P) -> Result<Self, P::Error>
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.
Sourcepub fn with_flags(self, value: GeneratorFlags) -> Self
pub fn with_flags(self, value: GeneratorFlags) -> Self
Add the passed GeneratorFlags
flags the generator should use for generating the code.
Sourcepub fn with_type_postfix<S: Into<String>>(
self,
type_: IdentType,
postfix: S,
) -> Self
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.
Sourcepub fn with_type(self, ident: Ident) -> Result<Self, Error>
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"));
Sourcepub fn generate_type(
self,
ident: Ident,
) -> Result<GeneratorFixed<'types>, Error>
pub fn generate_type( self, ident: Ident, ) -> Result<GeneratorFixed<'types>, Error>
Will fix the generator by call into_fixed
and then
generate_type
.
Sourcepub fn generate_named_types(self) -> Result<GeneratorFixed<'types>, Error>
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
.
Sourcepub fn generate_all_types(self) -> Result<GeneratorFixed<'types>, Error>
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
.
Sourcepub fn into_fixed(self) -> GeneratorFixed<'types>
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.