diff --git a/mavlink-bindgen/src/lib.rs b/mavlink-bindgen/src/lib.rs index 22f1efa2ce..167ce52780 100644 --- a/mavlink-bindgen/src/lib.rs +++ b/mavlink-bindgen/src/lib.rs @@ -39,7 +39,7 @@ fn _generate( ) -> Result { let mut bindings = vec![]; - for entry_maybe in read_dir(&definitions_dir).map_err(|source| { + for entry_maybe in read_dir(definitions_dir).map_err(|source| { BindGenError::CouldNotReadDefinitionsDirectory { source, path: definitions_dir.to_path_buf(), @@ -67,7 +67,7 @@ fn _generate( })?); // generate code - parser::generate(&definitions_dir, &definition_file, &mut outf)?; + parser::generate(definitions_dir, &definition_file, &mut outf)?; bindings.push(GeneratedBinding { module_name, diff --git a/mavlink-bindgen/src/parser.rs b/mavlink-bindgen/src/parser.rs index e6ee66f3ab..1ff3aa0f81 100644 --- a/mavlink-bindgen/src/parser.rs +++ b/mavlink-bindgen/src/parser.rs @@ -7,7 +7,6 @@ use std::fs::File; use std::io::{BufReader, Write}; use std::path::{Path, PathBuf}; use std::str::FromStr; -use std::u32; use quick_xml::{events::Event, Reader}; @@ -330,7 +329,7 @@ impl MavEnum { value = quote!(#cnt); } else { let tmp_value = enum_entry.value.unwrap(); - cnt = cnt.max(tmp_value as u32); + cnt = cnt.max(tmp_value); let tmp = TokenStream::from_str(&tmp_value.to_string()).unwrap(); value = quote!(#tmp); }; @@ -366,7 +365,7 @@ impl MavEnum { #[cfg(feature = "emit-description")] let description = if let Some(description) = self.description.as_ref() { - let desc = format!("{description}"); + let desc = description.to_string(); quote!(#[doc = #desc]) } else { quote!() @@ -1007,7 +1006,7 @@ pub enum MavXmlElement { Extensions, } -fn identify_element(s: &[u8]) -> Option { +const fn identify_element(s: &[u8]) -> Option { use self::MavXmlElement::*; match s { b"version" => Some(Version), @@ -1072,7 +1071,7 @@ pub fn parse_profile( let mut events: Vec> = Vec::new(); let file = File::open(&in_path).map_err(|e| BindGenError::CouldNotReadDefinitionFile { source: e, - path: in_path.to_path_buf(), + path: in_path.clone(), })?; let mut reader = Reader::from_reader(BufReader::new(file)); reader.trim_text(true); @@ -1127,10 +1126,10 @@ pub fn parse_profile( mavenum = Default::default(); } MavXmlElement::Entry => { - entry = Default::default(); + entry = MavEnumEntry::default(); } MavXmlElement::Include => { - include = Default::default(); + include = PathBuf::default(); } MavXmlElement::Param => { paramid = None; @@ -1245,7 +1244,7 @@ pub fn parse_profile( if entry.params.is_none() { entry.params = Some(vec![]); } - if let b"index" = attr.key.into_inner() { + if attr.key.into_inner() == b"index" { let s = std::str::from_utf8(&attr.value).unwrap(); paramid = Some(s.parse::().unwrap()); } @@ -1259,7 +1258,7 @@ pub fn parse_profile( is_in_extension = true; } b"entry" => { - entry = Default::default(); + entry = MavEnumEntry::default(); for attr in bytes.attributes() { let attr = attr.unwrap(); match attr.key.into_inner() { @@ -1319,7 +1318,7 @@ pub fn parse_profile( eprintln!("TODO: deprecated {s:?}"); } data => { - panic!("unexpected text data {:?} reading {:?}", data, s); + panic!("unexpected text data {data:?} reading {s:?}"); } } } @@ -1497,7 +1496,7 @@ impl MavXmlFilter { } !self.extension_filter.is_in } - Err(error) => panic!("Failed to filter XML: {}", error), + Err(error) => panic!("Failed to filter XML: {error}"), } } }