init
This commit is contained in:
247 files changed
+35538
No files matched your search
@@ -0,0 +1,88 @@
|
||||
<#@ template cleanws="true" #>
|
||||
/// A `PropertyId` identifies a single attribute in the data structure of a
|
||||
/// connection.
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum PropertyId {
|
||||
<# for struc in &self.structs { #>
|
||||
<#= struc.name #><#= struc.get_ids(&self.structs) #>,
|
||||
<# } #>
|
||||
|
||||
<# for struc in self.structs.iter().filter(|s| !s.opt) {
|
||||
for p in struc.get_properties(&self.structs) { #>
|
||||
<#= struc.name #><#= p.get_name() #><#= p.get_ids(&self.structs, struc) #>,
|
||||
<# }
|
||||
} #>
|
||||
}
|
||||
|
||||
/// A `PropertyValue` contains the value of an attribute in the data structures.
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum PropertyValue {
|
||||
<# for struc in &self.structs { #>
|
||||
<#= struc.name #>(<#= struc.get_type()? #>),
|
||||
<# } #>
|
||||
|
||||
<#
|
||||
let mut done = HashSet::new();
|
||||
for struc in self.structs.iter().filter(|s| !s.opt) {
|
||||
for p in struc.get_properties(&self.structs) {
|
||||
let type_s = p.get_inner_type()?;
|
||||
if !done.insert(type_s.to_string()) {
|
||||
continue;
|
||||
}
|
||||
#>
|
||||
<#= p.get_inner_type_as_name()? #>(<#= type_s #>),
|
||||
<# }
|
||||
} #>
|
||||
}
|
||||
|
||||
/// A `PropertyValueRef` contains a reference to the value of an attribute in
|
||||
/// the data structures.
|
||||
///
|
||||
/// See [`PropertyValue`] for the owned variant.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PropertyValueRef<'a> {
|
||||
<# for struc in &self.structs { #>
|
||||
<#= struc.name #>(<#= struc.get_type()?.lifetime(true).to_ref(true) #>),
|
||||
<# } #>
|
||||
|
||||
<#
|
||||
let mut done = HashSet::new();
|
||||
for struc in self.structs.iter().filter(|s| !s.opt) {
|
||||
for p in struc.get_properties(&self.structs) {
|
||||
let type_s = p.get_inner_type()?;
|
||||
if !done.insert(type_s.to_string()) {
|
||||
continue;
|
||||
}
|
||||
#>
|
||||
<#= p.get_inner_type_as_name()? #>(<#= p.get_inner_type()?.lifetime(true).to_ref(true) #>),
|
||||
<# }
|
||||
} #>
|
||||
}
|
||||
|
||||
impl PropertyValue {
|
||||
pub fn as_ref(&self) -> PropertyValueRef<'_> {
|
||||
match self {
|
||||
<# for struc in &self.structs { #>
|
||||
PropertyValue::<#= struc.name #>(s) => PropertyValueRef::<#= struc.name #>(<#= struc.get_type()?.code_as_ref("s").trim_start_matches('&') #>),
|
||||
<# } #>
|
||||
|
||||
<#
|
||||
let mut done = HashSet::new();
|
||||
for struc in self.structs.iter().filter(|s| !s.opt) {
|
||||
for p in struc.get_properties(&self.structs) {
|
||||
let inner_type = p.get_inner_type()?;
|
||||
if !done.insert(inner_type.to_string()) {
|
||||
continue;
|
||||
}
|
||||
let name = inner_type.to_name();
|
||||
let has_ref = inner_type.lifetime(true).to_ref(true).uses_lifetime();
|
||||
#>
|
||||
PropertyValue::<#= name #>(s) => PropertyValueRef::<#= name #>(<#= inner_type.wrap_ref().code_as_ref("s").trim_start_matches('&') #>),
|
||||
<# }
|
||||
} #>
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user