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

Replace FunctionCode type alias with enum #236

Merged
merged 8 commits into from
Jan 3, 2024
Merged

Replace FunctionCode type alias with enum #236

merged 8 commits into from
Jan 3, 2024

Conversation

benjamin-nw
Copy link
Contributor

@benjamin-nw benjamin-nw commented Dec 27, 2023

This PR try to improve the usability of the FunctionCode type by adding an enum with modbus public function code, as well a custom function code defined by the user.

The goal is to reduce code duplication and ease the use of the FunctionCode in order to avoid mistakes.

It also adds the ability to retrieve the FunctionCode associated with a Request/Response.

This will be useful in the futur when we try to implement #165 because we need to have access to the type of Request we are handling in case of an error in the server.

I took inspiration from the work in #226 .

This is a Breaking Change as we are updating a Public type.

@benjamin-nw benjamin-nw changed the title Change FunctionCode Change FunctionCode type alias into an enum Dec 27, 2023
@benjamin-nw benjamin-nw marked this pull request as ready for review December 27, 2023 10:44
@benjamin-nw benjamin-nw changed the title Change FunctionCode type alias into an enum Update FunctionCode type alias into an enum Dec 27, 2023
src/frame/mod.rs Outdated
}
}

impl From<FunctionCode> for u8 {
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we really want this implicit conversion.

Copy link
Member

Choose a reason for hiding this comment

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

FunctionCode -> u8: Ok. But what is the public use case?
u8 -> FunctionCode: Not recommended!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FunctionCode -> u8: Ok. But what is the public use case?

None I think, the user only needs to use the enum variant. Thus, I could remove them both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the new and value functions be public too then ?

src/frame/mod.rs Outdated
}
}

impl From<u8> for FunctionCode {
Copy link
Member

Choose a reason for hiding this comment

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

... same here.

src/frame/mod.rs Outdated Show resolved Hide resolved
src/frame/mod.rs Show resolved Hide resolved
src/frame/mod.rs Show resolved Hide resolved
@uklotzde
Copy link
Member

uklotzde commented Jan 2, 2024

The only thing that's missing now is a changelog entry.

@uklotzde uklotzde added this to the v0.10.0 milestone Jan 2, 2024
@benjamin-nw
Copy link
Contributor Author

How do you want to handle the release of the 0.10 version ?

Do you push everything on main until the new version is released ? Or do you have a branch for a new version ?

Can I add the ## 0.10.0 (Unreleased) entry in the Changelog here ?

My issue is, will other PR for 0.10 be able to access this changes on main or another branch ?

@uklotzde
Copy link
Member

uklotzde commented Jan 2, 2024

Please cherry-pick the commit from #239 and add an entry for this PR to avoid merge conflicts. The commits will be squashed when we merge this PR afterwards.

@uklotzde
Copy link
Member

uklotzde commented Jan 2, 2024

We usually only do trunk based development. If someone needs to maintain a legacy version for an extended period of time they could fork the repo.

@benjamin-nw
Copy link
Contributor Author

First time doing a cherry-pick.

I've first rebased on main and then cherry-picked your commit.

Did I do it right ?

@uklotzde
Copy link
Member

uklotzde commented Jan 2, 2024

After

First time doing a cherry-pick.

I've first rebased on main and then cherry-picked your commit.

Did I do it right ?

Never rebase, only merge main. Otherwise all review comments become dangling.

CHANGELOG.md Outdated Show resolved Hide resolved
@benjamin-nw benjamin-nw changed the title Update FunctionCode type alias into an enum Replace FunctionCode type alias with enum Jan 3, 2024
@uklotzde uklotzde merged commit f4039fd into slowtec:main Jan 3, 2024
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