Skip to content

Commit

Permalink
fix: struct rules
Browse files Browse the repository at this point in the history
  • Loading branch information
leoadonia committed Oct 29, 2024
1 parent 65e13aa commit 0336ca9
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions core/src/ten_rust/src/pkg_info/graph/msg_conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ pub struct MsgConversionRules {
pub keep_original: Option<bool>,
}

impl MsgConversionRules {
pub fn validate(&self) -> Result<()> {
if self.rules.is_empty() {
return Err(anyhow::anyhow!("conversion rules are empty"));
}

for (idx, rule) in self.rules.iter().enumerate() {
rule.validate()
.map_err(|e| anyhow::anyhow!("- rule[{}]: {}", idx, e))?;
}

Ok(())
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MsgConversion {
#[serde(rename = "type")]
Expand All @@ -112,18 +127,7 @@ pub struct MsgConversion {

impl MsgConversion {
pub fn validate(&self) -> Result<()> {
if self.rules.rules.is_empty() {
return Err(anyhow::Error::msg(
"message conversion rules are empty",
));
}

for (idx, rule) in self.rules.rules.iter().enumerate() {
rule.validate()
.map_err(|e| anyhow::anyhow!("- rule[{}]: {}", idx, e))?;
}

Ok(())
self.rules.validate()
}
}

Expand Down

0 comments on commit 0336ca9

Please sign in to comment.