Skip to content

Conversation

@notoriaga
Copy link
Contributor

No description provided.

const MESSAGE_TYPES: &'static [u16] = &[T::MESSAGE_TYPE];

fn from_sbp(msg: SBP) -> Self {
msg.try_into().unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fallible? At least should use .expect unless we never expect .unwrap to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't ever fail, because from_sbp is only called after checking that the message was in MESSAGE_TYPES. So if you create a custom event and set the wrong messages types you could hit this error. So an expect is probably a good idea to make that more clear

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, expect could point out that it should only happen if there's a programming error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well so actually this shouldn't ever error, this blanket impl makes all ConcreteMessages usable as events triggered by that messages type. So baring a logic error in the Link (i.e. sending an event to the wrong handler or something) this should never happen. Replaced the unwrap with a panic that will include the offending message just in case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

self.stateless_link.clone()
}

pub fn send_state<M>(&self, state: &S, msg: M) -> bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn send_state<M>(&self, state: &S, msg: M) -> bool
pub fn send_with_state<M>(&self, state: &S, msg: M) -> bool

Maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let link = source.link();
let count = RefCell::new(0);

link.register(|count: &RefCell<usize>, _: SBP| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test receiving an ObsMsg struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup good catch

@notoriaga notoriaga changed the title Rust: at link data structure Rust: callback based message handler Sep 13, 2021
@notoriaga notoriaga merged commit 0f35aac into master Sep 13, 2021
@notoriaga notoriaga deleted the steve/link branch September 13, 2021 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants