Skip to content

Commit

Permalink
address some lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Aug 25, 2024
1 parent cfa4d2a commit 230f7d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions mavlink-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn _generate(
) -> Result<GeneratedBindings, BindGenError> {
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(),
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 18 additions & 22 deletions mavlink-bindgen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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!()
Expand Down Expand Up @@ -1007,7 +1006,7 @@ pub enum MavXmlElement {
Extensions,
}

fn identify_element(s: &[u8]) -> Option<MavXmlElement> {
const fn identify_element(s: &[u8]) -> Option<MavXmlElement> {
use self::MavXmlElement::*;
match s {
b"version" => Some(Version),
Expand Down Expand Up @@ -1072,7 +1071,7 @@ pub fn parse_profile(
let mut events: Vec<Result<Event, quick_xml::Error>> = 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);
Expand All @@ -1095,14 +1094,11 @@ pub fn parse_profile(
for e in events {
match e {
Ok(Event::Start(bytes)) => {
let id = match identify_element(bytes.name().into_inner()) {
None => {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
}
Some(kind) => kind,
let Some(id) = identify_element(bytes.name().into_inner()) else {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
};

assert!(
Expand All @@ -1117,20 +1113,20 @@ pub fn parse_profile(
is_in_extension = true;
}
MavXmlElement::Message => {
message = Default::default();
message = MavMessage::default();
}
MavXmlElement::Field => {
field = Default::default();
field = MavField::default();
field.is_extension = is_in_extension;
}
MavXmlElement::Enum => {
mavenum = Default::default();
mavenum = MavEnum::default();
}
MavXmlElement::Entry => {
entry = Default::default();
entry = MavEnumEntry::default();
}
MavXmlElement::Include => {
include = Default::default();
include = PathBuf::default();
}
MavXmlElement::Param => {
paramid = None;
Expand Down Expand Up @@ -1245,7 +1241,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::<usize>().unwrap());
}
Expand All @@ -1259,7 +1255,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() {
Expand Down Expand Up @@ -1319,7 +1315,7 @@ pub fn parse_profile(
eprintln!("TODO: deprecated {s:?}");
}
data => {
panic!("unexpected text data {:?} reading {:?}", data, s);
panic!("unexpected text data {data:?} reading {s:?}");
}
}
}
Expand Down Expand Up @@ -1497,7 +1493,7 @@ impl MavXmlFilter {
}
!self.extension_filter.is_in
}
Err(error) => panic!("Failed to filter XML: {}", error),
Err(error) => panic!("Failed to filter XML: {error}"),
}
}
}

0 comments on commit 230f7d7

Please sign in to comment.