Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new rust clippy #1292

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::*;

((*- macro compare_value(prefix, value) *))
((*- if value is string_type *))
assert_eq!(msg.(((prefix|snake_case))).to_string(), (((value|str_escape))), "incorrect value for msg.(((prefix|snake_case))), expected string '{}', is '{}'", (((value|str_escape))), msg.(((prefix|snake_case))));
assert_eq!(msg.(((prefix|snake_case))).as_bytes(), (((value|bytes_escape))), "incorrect value for msg.(((prefix|snake_case))), expected string '{:?}', is '{:?}'", (((value|bytes_escape))), msg.(((prefix|snake_case))).as_bytes());
((*- elif value is array_type *))
((*- for ff in value *))((( compare_value( (((prefix|snake_case))) + '[' + (((loop.index0|to_str))) + ']', (((ff))) ) )))((*- endfor *))
((*- elif value is dict_type *))
Expand Down Expand Up @@ -52,7 +52,7 @@ fn test_(((s.suite_name|snake_case)))()
sbp::messages::Sbp::(((t.msg.name|lower_acronyms)))(msg) => {
assert_eq!( msg.message_type(), (((t.msg_type))), "Incorrect message type, expected (((t.msg_type))), is {}", msg.message_type());
let sender_id = msg.sender_id().unwrap();
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {}", sender_id);
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {sender_id}");
((*- for f in t.fieldskeys *))(((compare_value( (((f))), (((t.fields[f]))) ))))((*- endfor *))
},
_ => panic!("Invalid message type! Expected a (((t.msg.name)))"),
Expand Down Expand Up @@ -98,7 +98,7 @@ fn test_json2sbp_(((s.suite_name|snake_case)))()
sbp::messages::Sbp::(((t.msg.name|lower_acronyms)))(msg) => {
assert_eq!( msg.message_type(), (((t.msg_type))), "Incorrect message type, expected (((t.msg_type))), is {}", msg.message_type());
let sender_id = msg.sender_id().unwrap();
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {}", sender_id);
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {sender_id}");
((*- for f in t.fieldskeys *))(((compare_value( (((f))), (((t.fields[f]))) ))))((*- endfor *))
},
_ => panic!("Invalid message type! Expected a (((t.msg.name)))"),
Expand Down Expand Up @@ -141,7 +141,7 @@ fn test_sbp2json_(((s.suite_name|snake_case)))()
sbp::messages::Sbp::(((t.msg.name|lower_acronyms)))(msg) => {
assert_eq!( msg.message_type(), (((t.msg_type))), "Incorrect message type, expected (((t.msg_type))), is {}", msg.message_type());
let sender_id = msg.sender_id().unwrap();
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {}", sender_id);
assert_eq!(sender_id, (((t.sbp.sender))), "incorrect sender id, expected (((t.sbp.sender))), is {sender_id}");
((*- for f in t.fieldskeys *))(((compare_value( (((f))), (((t.fields[f]))) ))))((*- endfor *))
},
_ => panic!("Invalid message type! Expected a (((t.msg.name)))"),
Expand Down
6 changes: 3 additions & 3 deletions generator/sbpg/targets/test_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
TEST_TEMPLATE_NAME = "rust/test/sbp_tests_template.rs"
TEST_MAIN_TEMPLATE_NAME = "rust/test/sbp_tests_main_template.rs"

def str_escape(value):
return "\"{}\"".format(value)
def bytes_escape(value):
return "&{}".format(list(bytes(value, "ascii")))

def mod_name(value):
return value.split('.')[1]

JENV.filters['to_str'] = to_str
JENV.filters['str_escape'] = str_escape
JENV.filters['bytes_escape'] = bytes_escape
JENV.filters['sorted'] = sorted
JENV.filters['mod_name'] = mod_name
JENV.filters['lower_acronyms'] = lower_acronyms
Expand Down
2 changes: 1 addition & 1 deletion rust/sbp/examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
Ok(Sbp::MsgLog(x)) => println!("{}", x.text),
Ok(Sbp::MsgPosLlh(x)) => println!("{} {} {}", x.lat, x.lon, x.height),
Err(e) => {
eprintln!("{:?}", e);
eprintln!("{e:?}");
break;
}
_ => {}
Expand Down
8 changes: 4 additions & 4 deletions rust/sbp/src/sbp_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<'de, E, const LEN: usize> serde::Deserialize<'de> for SbpString<[u8; LEN],
Er: Error,
{
let data = v.as_bytes().try_into().map_err(|_| {
Error::custom(format!("was expecting a string of length {}", LEN))
Error::custom(format!("was expecting a string of length {LEN}"))
})?;
Ok(SbpString::new(data))
}
Expand All @@ -236,7 +236,7 @@ impl<'de, E, const LEN: usize> serde::Deserialize<'de> for SbpString<[u8; LEN],
Er: Error,
{
let data = v.into_bytes().try_into().map_err(|_| {
Error::custom(format!("was expecting a string of length {}", LEN))
Error::custom(format!("was expecting a string of length {LEN}"))
})?;
Ok(SbpString::new(data))
}
Expand All @@ -246,7 +246,7 @@ impl<'de, E, const LEN: usize> serde::Deserialize<'de> for SbpString<[u8; LEN],
Er: Error,
{
let data = v.try_into().map_err(|_| {
Error::custom(format!("was expecting a string of length {}", LEN))
Error::custom(format!("was expecting a string of length {LEN}"))
})?;
Ok(SbpString::new(data))
}
Expand All @@ -256,7 +256,7 @@ impl<'de, E, const LEN: usize> serde::Deserialize<'de> for SbpString<[u8; LEN],
Er: Error,
{
let data = v.try_into().map_err(|_| {
Error::custom(format!("was expecting a string of length {}", LEN))
Error::custom(format!("was expecting a string of length {LEN}"))
})?;
Ok(SbpString::new(data))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(8.24194335937500000e+03),
Expand Down Expand Up @@ -95,8 +94,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(7.49267639160156250e+02),
Expand Down Expand Up @@ -147,8 +145,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-6.49365283203125000e+03),
Expand Down Expand Up @@ -200,8 +197,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-9.99023498535156250e+02),
Expand Down Expand Up @@ -252,8 +248,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(4.74536132812500000e+03),
Expand Down Expand Up @@ -304,8 +299,7 @@ fn test_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-4.99511749267578125e+02),
Expand Down Expand Up @@ -377,8 +371,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(8.24194335937500000e+03),
Expand Down Expand Up @@ -436,8 +429,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(7.49267639160156250e+02),
Expand Down Expand Up @@ -495,8 +487,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-6.49365283203125000e+03),
Expand Down Expand Up @@ -554,8 +545,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-9.99023498535156250e+02),
Expand Down Expand Up @@ -613,8 +603,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(4.74536132812500000e+03),
Expand Down Expand Up @@ -672,8 +661,7 @@ fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-4.99511749267578125e+02),
Expand Down Expand Up @@ -752,8 +740,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(8.24194335937500000e+03),
Expand Down Expand Up @@ -823,8 +810,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(7.49267639160156250e+02),
Expand Down Expand Up @@ -894,8 +880,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-6.49365283203125000e+03),
Expand Down Expand Up @@ -966,8 +951,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-9.99023498535156250e+02),
Expand Down Expand Up @@ -1037,8 +1021,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(4.74536132812500000e+03),
Expand Down Expand Up @@ -1108,8 +1091,7 @@ fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result_dep_a() {
let sender_id = msg.sender_id().unwrap();
assert_eq!(
sender_id, 0x4c3,
"incorrect sender id, expected 0x4c3, is {}",
sender_id
"incorrect sender id, expected 0x4c3, is {sender_id}"
);
assert!(
msg.cf.almost_eq(-4.99511749267578125e+02),
Expand Down
Loading