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

Check the parameter names to ensure there are no duplicates after parsing a route #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gameldar
Copy link

Description

After parsing a route go through the parameter names to ensure there aren't duplicates. If there are panic so we abort at initial creation.

Note this changes the add method to now return a Result (so warning will be produced with existing usage about an unused return value).

Motivation and Context

Closes #34

How Has This Been Tested?

Unit tests exist for the new conditions

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@gameldar
Copy link
Author

Not sure if we want to do this as is (original commit enforced a panic instead... which again is undesirable for a library crate) - it does introduce a return value for the add method. Alternatively we could introduce a add_and_validate (or something like that) that allow you to choose to validate the names and potentially deprecate the old implementation?

@Nemo157
Copy link
Contributor

Nemo157 commented Aug 19, 2019

One idea would be to add a builder, so you would add routes to the builder then get the Router back when you finalize it. That would allow delaying the error from the add method to a finish method, so you only have to deal with a Result in one place (presumably by expecting it in most uses).

Alternatively, there could be two add methods, maybe an add_checked that returns a Result and have add just unwrap that result, so if users were dynamically loading their routes they would have the option of dealing with errors in them, while most users with statically defined routes will just get a panic if they screw one up.

Gameldar added 3 commits August 21, 2019 22:08
add calls add_check and unwraps it

Also added a bit of documentation around the router and the add methods
@gameldar gameldar force-pushed the 34-duplicate-parameter-names branch from 11a9b0b to fa0f7d6 Compare August 21, 2019 16:14
@goto-bus-stop goto-bus-stop changed the base branch from master to main August 9, 2020 12:56
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.

Duplicate named parameters in route
2 participants