Skip to content
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
6 changes: 6 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
command: fmt
args: -- --check

- uses: actions-rs/cargo@v1
name: Lint Check
with:
command: clippy
args: --all-features --all-targets -- -D warnings

test:
name: Tests
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

// This file was auto-generated. Do not modify by hand!

#![allow(clippy::excessive_precision)]

((*- for test_name in test_names *))
mod (((test_name)));
((*- endfor *))
Expand Down
2 changes: 1 addition & 1 deletion generator/sbpg/targets/test_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
TEST_MAIN_TEMPLATE_NAME = "rust/test/sbp_tests_main_template.rs"

def str_escape(value):
return "\"{}\".to_string()".format(value)
return "\"{}\"".format(value)

def mod_name(value):
return value.split('.')[1]
Expand Down
9 changes: 3 additions & 6 deletions rust/sbp/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<R: futures::AsyncRead + Unpin> futures::Stream for Decoder<R> {
) -> std::task::Poll<Option<Self::Item>> {
let frame = match futures::ready!(std::pin::Pin::new(&mut self.0).poll_next(cx)) {
Some(Ok(frame)) => frame,
Some(Err(e)) => return std::task::Poll::Ready(Some(Err(e.into()))),
Some(Err(e)) => return std::task::Poll::Ready(Some(Err(e))),
None => return std::task::Poll::Ready(None),
};
std::task::Poll::Ready(Some(frame.to_sbp()))
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<R: futures::AsyncRead + Unpin> futures::Stream for TimeoutDecoder<R> {
) -> std::task::Poll<Option<Self::Item>> {
match futures::ready!(std::pin::Pin::new(&mut self.0).poll_next(cx)) {
Some(Ok(frame)) => std::task::Poll::Ready(Some(frame.to_sbp())),
Some(Err(e)) => std::task::Poll::Ready(Some(Err(e.into()))),
Some(Err(e)) => std::task::Poll::Ready(Some(Err(e))),
None => std::task::Poll::Ready(None),
}
}
Expand Down Expand Up @@ -381,10 +381,7 @@ mod tests {
let timeout_duration = Duration::from_secs(2);
let now = Instant::now();
let mut messages = iter_messages_with_timeout(rdr, timeout_duration);
for msg in &mut messages {
assert!(matches!(msg, Err(Error::IoError(_))));
break;
}
assert!(matches!(messages.next().unwrap(), Err(Error::IoError(_))));
assert!(now.elapsed() >= timeout_duration);
}

Expand Down
7 changes: 4 additions & 3 deletions rust/sbp/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
{
let mut handlers = self.link.inner.handlers.lock().unwrap();
for handler in handlers.values_mut() {
if handler.can_run(&msg) {
if handler.can_run(msg) {
handler.run(state, msg.clone());
sent = true;
}
Expand All @@ -58,7 +58,7 @@ where
{
let mut handlers = self.stateless_link.inner.handlers.lock().unwrap();
for handler in handlers.values_mut() {
if handler.can_run(&msg) {
if handler.can_run(msg) {
handler.run(&(), msg.clone());
sent = true;
}
Expand Down Expand Up @@ -142,6 +142,7 @@ struct LinkInner<'link, S> {
}

/// A message handler and the message ids it responds to.
#[allow(clippy::type_complexity)]
pub struct Handler<'link, S> {
func: Box<dyn FnMut(&S, Sbp) + Send + 'link>,
msg_types: Cow<'static, [u16]>,
Expand Down Expand Up @@ -225,7 +226,7 @@ slotmap::new_key_type! {
}

/// Returned when registering a callback. Can be used to unregister the callback.
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Key {
key: KeyInner,
}
Expand Down
8 changes: 4 additions & 4 deletions rust/sbp/src/sbp_iter_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ mod tests {

let mut with_time = iter_messages(data).ignore_errors().with_rover_time();

let gps_time = with_time.next().map(|(_, t)| t).flatten().unwrap().unwrap();
let gps_time = with_time.next().and_then(|(_, t)| t).unwrap().unwrap();
assert_eq!(gps_time.wn(), 1787);
assert!((gps_time.tow() - 2567.8).abs() < f64::EPSILON);

assert!(with_time.next().map(|(_, t)| t).flatten().is_none());
assert!(with_time.next().and_then(|(_, t)| t).is_none());

let gps_time = with_time.next().map(|(_, t)| t).flatten().unwrap().unwrap();
let gps_time = with_time.next().and_then(|(_, t)| t).unwrap().unwrap();
assert_eq!(gps_time.wn(), 1787);
assert!((gps_time.tow() - 2567.9).abs() < f64::EPSILON);

let gps_time = with_time.next().map(|(_, t)| t).flatten().unwrap().unwrap();
let gps_time = with_time.next().and_then(|(_, t)| t).unwrap().unwrap();
assert_eq!(gps_time.wn(), 1787);
assert!((gps_time.tow() - 2568.).abs() < f64::EPSILON);
}
Expand Down
4 changes: 2 additions & 2 deletions rust/sbp/src/sbp_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ mod tests {
// Auto generate alternating bytes [`from_parts`] section
// -----
let parts = ["a", "b", "c"];
let multipart = SbpString::<_, Multipart>::from_parts(&parts);
let multipart = SbpString::<_, Multipart>::from_parts(parts);
assert_eq!(multipart.data, null);

// Test [`parts`] section
Expand Down Expand Up @@ -525,7 +525,7 @@ mod tests {
// Auto generate alternating bytes [`from_parts`] section
// -----
let parts = ["a", "b", "c"];
let double_null = SbpString::<_, DoubleNullTerminated>::from_parts(&parts);
let double_null = SbpString::<_, DoubleNullTerminated>::from_parts(parts);
assert_eq!(double_null.data, data);

// Test [`parts`] section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ fn test_auto_check_sbp_bootload_msg_bootloader_handshake_resp() {
assert_eq!(
msg.version.to_string(),
"v1.2
"
.to_string(),
",
"incorrect value for msg.version, expected string '{}', is '{}'",
"v1.2
"
.to_string(),
",
msg.version
);
}
Expand Down Expand Up @@ -173,12 +171,10 @@ fn test_json2sbp_auto_check_sbp_bootload_msg_bootloader_handshake_resp() {
assert_eq!(
msg.version.to_string(),
"v1.2
"
.to_string(),
",
"incorrect value for msg.version, expected string '{}', is '{}'",
"v1.2
"
.to_string(),
",
msg.version
);
}
Expand Down Expand Up @@ -308,12 +304,10 @@ fn test_sbp2json_auto_check_sbp_bootload_msg_bootloader_handshake_resp() {
assert_eq!(
msg.version.to_string(),
"v1.2
"
.to_string(),
",
"incorrect value for msg.version, expected string '{}', is '{}'",
"v1.2
"
.to_string(),
",
msg.version
);
}
Expand Down
12 changes: 6 additions & 6 deletions rust/sbp/tests/integration/auto_check_sbp_logging_msg_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ fn test_auto_check_sbp_logging_msg_log() {
);
assert_eq!(
msg.text.to_string(),
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
"incorrect value for msg.text, expected string '{}', is '{}'",
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
msg.text
);
}
Expand Down Expand Up @@ -120,9 +120,9 @@ fn test_json2sbp_auto_check_sbp_logging_msg_log() {
);
assert_eq!(
msg.text.to_string(),
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
"incorrect value for msg.text, expected string '{}', is '{}'",
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
msg.text
);
}
Expand Down Expand Up @@ -194,9 +194,9 @@ fn test_sbp2json_auto_check_sbp_logging_msg_log() {
);
assert_eq!(
msg.text.to_string(),
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
"incorrect value for msg.text, expected string '{}', is '{}'",
"Filtered all obs from 2314 at tow 83.539019".to_string(),
"Filtered all obs from 2314 at tow 83.539019",
msg.text
);
}
Expand Down
Loading