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, 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)]
pub struct MyType(pub i32);
#[derive(Debug, Default)]
pub struct MyListType(pub Vec<IntType>);
#[derive(Debug)]
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 moreSource§impl Debug for TypedefMode
impl Debug for TypedefMode
Source§impl Default for TypedefMode
impl Default for TypedefMode
Source§fn default() -> TypedefMode
fn default() -> TypedefMode
Source§impl PartialEq for TypedefMode
impl PartialEq for TypedefMode
impl Copy for TypedefMode
impl Eq for TypedefMode
impl StructuralPartialEq for TypedefMode
Auto Trait Implementations§
impl Freeze for TypedefMode
impl RefUnwindSafe for TypedefMode
impl Send for TypedefMode
impl Sync for TypedefMode
impl Unpin for TypedefMode
impl UnwindSafe for TypedefMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.