-
Notifications
You must be signed in to change notification settings - Fork 134
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
refactor all the repetitive code in roles-logic-sv2 parsers file into macros #67
Comments
In |
Hi @rrybarczyk, I would like to work on this issue. |
Hi @pavlenex, I've got some time and I'd like to contribute. I already looked at this issue back in November. Is it still relevant? |
@vjtch fantastic! I am not sure if it is still relevant. You can look at the file and see if you find any duplicate logic that can be modularized. You can also look at the history of this file and see if you find any commits that look like it is addressing this issue. If you don't see anything that looks like it has consolidate the logic, I would say it is still a valid issue. @Fi3 will be able to confirm better than I can though. |
@rrybarczyk there is still some duplicated logic. For example this impl<'a> TryFrom<(u8, &'a mut [u8])> for CommonMessages<'a> {
type Error = Error;
fn try_from(v: (u8, &'a mut [u8])) -> Result<Self, Self::Error> {
let msg_type: CommonMessageTypes = v.0.try_into()?;
match msg_type {
CommonMessageTypes::SetupConnection => {
let message: SetupConnection<'a> = from_bytes(v.1)?;
Ok(CommonMessages::SetupConnection(message))
}
CommonMessageTypes::SetupConnectionSuccess => {
let message: SetupConnectionSuccess = from_bytes(v.1)?;
Ok(CommonMessages::SetupConnectionSuccess(message))
}
// ...
}
}
} can be rewrited to macro_rules! try_from_for_common_messages {
( [ $( $variant:ident $( < $lifetime:lifetime > )? ),+ ] ) => {
impl<'a> TryFrom<(u8, &'a mut [u8])> for CommonMessages<'a> {
type Error = Error;
fn try_from(v: (u8, &'a mut [u8])) -> Result<Self, Self::Error> {
let msg_type: CommonMessageTypes = v.0.try_into()?;
match msg_type {
$(
CommonMessageTypes::$variant => {
let message: $variant $( <$lifetime> )? = from_bytes(v.1)?;
Ok(CommonMessages::$variant(message))
}
)+
}
}
}
};
}
try_from_for_common_messages!([SetupConnection<'a>, SetupConnectionSuccess, SetupConnectionError<'a>, ChannelEndpointChanged]); In this example there are only 4 variants of enum but there are similiar |
cc @jbesraa perhaps this issue is now duplication of some of other issues/pr's, it seems so, if not we can cross reference it in a tracker since this seems to be refactoring work. |
@pavlenex can you list the issue or PRs that this may be a duplicate of? Anytime an issue like this pops up, we need to be diligent about adding it to #845. I just edited #845's issue to include two segments: 1) Rust Docs (this is pretty filled out) and 2) Refactor Implementation (new subsection addition). I linked this issue under the Refactor Implementation subsection to kick it off. |
We did not refactor any repetitive code in |
No description provided.
The text was updated successfully, but these errors were encountered: