Unmodified copy of the tsclientlib workspace crates (MIT OR Apache-2.0) with the tsdeclarations submodule (83cb8a9) flattened into plain files. See crates/proto/UPSTREAM.md for the path mapping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
89 lines
2.5 KiB
Plaintext
89 lines
2.5 KiB
Plaintext
<#@ 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('&') #>),
|
|
<# }
|
|
} #>
|
|
}
|
|
}
|
|
}
|