pub enum TypedefMode {
Auto,
Typedef,
NewType,
}Expand description
Tells the Generator how to deal with type definitions.
Variants§
Auto
The Generator will automatically detect if a
new type struct or a simple type definition should be used
for a Reference type.
Detecting the correct type automatically depends basically on the occurrence of the references type. If the target type is only referenced exactly once, a type definition is rendered. If a different occurrence is used, it is wrapped in a new type struct because usually additional code needs to be implemented for such types.
§Examples
Consider the following XML schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com"
targetNamespace="http://example.com">
<xs:simpleType name="MyList">
<xs:list itemType="xs:int" />
</xs:simpleType>
<xs:simpleType name="MyType">
<xs:restriction base="xs:int" />
</xs:simpleType>
</xs:schema>If the typedef mode is set to TypedefMode::Auto the following code is rendered:
pub type MyType = i32;
#[derive(Debug, Clone, Default)]
pub struct MyListType(pub Vec<IntType>);
pub type IntType = i32;Typedef
The Generator will always use a simple type definition
for a Reference type.
§Examples
Consider the following XML schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com"
targetNamespace="http://example.com">
<xs:simpleType name="MyList">
<xs:list itemType="xs:int" />
</xs:simpleType>
<xs:simpleType name="MyType">
<xs:restriction base="xs:int" />
</xs:simpleType>
</xs:schema>If the typedef mode is set to TypedefMode::Typedef the following code is rendered:
pub type MyType = i32;
pub type MyListType = Vec<IntType>;
pub type IntType = i32;NewType
The Generator will always use a new type struct
for a Reference type.
§Examples
Consider the following XML schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com"
targetNamespace="http://example.com">
<xs:simpleType name="MyList">
<xs:list itemType="xs:int" />
</xs:simpleType>
<xs:simpleType name="MyType">
<xs:restriction base="xs:int" />
</xs:simpleType>
</xs:schema>If the typedef mode is set to TypedefMode::NewType the following code is rendered:
#[derive(Debug, Clone)]
pub struct MyType(pub i32);
#[derive(Debug, Clone, Default)]
pub struct MyListType(pub Vec<IntType>);
#[derive(Debug, Clone)]
pub struct IntType(pub i32);Trait Implementations§
Source§impl Clone for TypedefMode
impl Clone for TypedefMode
Source§fn clone(&self) -> TypedefMode
fn clone(&self) -> TypedefMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more