Skip to content

Commit 3296cd6

Browse files
onur-ozkanpatrickelectric
authored andcommitted
use Option for MavDeprecation.replaced_by in parser
replaced_by is not always provided, so it's better to store it as None rather than an empty String. This applies the following changes without any behavioral change: - Switch replaced_by to Option<String> in MavDeprecation. - Parse missing/blank replaced_by as None. - Update deprecated attribute formatting to handle Option. Signed-off-by: Onur Özkan <work@onurozkan.dev>
1 parent 29fe39e commit 3296cd6

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

mavlink-bindgen/src/parser.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,7 @@ impl MavType {
15041504
pub struct MavDeprecation {
15051505
// YYYY-MM
15061506
pub since: String,
1507-
// maybe empty, may be encapuslated in `` and contain a wildcard
1508-
pub replaced_by: String,
1507+
pub replaced_by: Option<String>,
15091508
pub note: Option<String>,
15101509
}
15111510

@@ -1517,12 +1516,10 @@ impl MavDeprecation {
15171516
Some(str) => format!("{str}."),
15181517
None => String::new(),
15191518
};
1520-
let replaced_by = if self.replaced_by.starts_with("`") {
1521-
format!("See {}", self.replaced_by)
1522-
} else if self.replaced_by.is_empty() {
1523-
String::new()
1524-
} else {
1525-
format!("See `{}`", self.replaced_by)
1519+
let replaced_by = match &self.replaced_by {
1520+
Some(str) if str.starts_with('`') => format!("See {str}"),
1521+
Some(str) => format!("See `{str}`"),
1522+
None => String::new(),
15261523
};
15271524
let message = format!("{note} {replaced_by} (Deprecated since {since})");
15281525
quote!(#[deprecated = #message])
@@ -1694,7 +1691,7 @@ pub fn parse_profile(
16941691
}
16951692
MavXmlElement::Deprecated => {
16961693
deprecated = Some(MavDeprecation {
1697-
replaced_by: String::new(),
1694+
replaced_by: None,
16981695
since: String::new(),
16991696
note: None,
17001697
});
@@ -1856,8 +1853,12 @@ pub fn parse_profile(
18561853
String::from_utf8_lossy(&attr.value).to_string();
18571854
}
18581855
b"replaced_by" => {
1859-
deprecated.as_mut().unwrap().replaced_by =
1860-
String::from_utf8_lossy(&attr.value).to_string();
1856+
let value = String::from_utf8_lossy(&attr.value);
1857+
deprecated.as_mut().unwrap().replaced_by = if value.is_empty() {
1858+
None
1859+
} else {
1860+
Some(value.to_string())
1861+
};
18611862
}
18621863
_ => (),
18631864
},

0 commit comments

Comments
 (0)