Fix Clippy warning in Routable macro#1975
Merged
ealmloff merged 2 commits intoDioxusLabs:mainfrom Feb 24, 2024
Merged
Conversation
ealmloff
reviewed
Feb 24, 2024
Member
There was a problem hiding this comment.
Part of the error types that the routable macro generates comes from the error type in different router traits including FromRouterSegments. Deriving Eq on the error enum requires each of those error types to implement Eq which causes this code to stop compiling on this branch:
#[rustfmt::skip]
#[derive(Routable, Clone, PartialEq)]
enum Route {
#[route("/:id")]
Blog { id: MyCustomType },
}
#[derive(Clone, Debug, PartialEq)]
struct MyCustomType;
impl std::fmt::Display for MyCustomType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "My Custom Type")
}
}
impl dioxus_router::routable::FromRouteSegment for MyCustomType {
// Any error type that implements PartialEq but not Eq currently compiles, but will fail to compile with this change
type Err = f32;
fn from_route_segment(route: &str) -> Result<Self, Self::Err> {
if route == "my-custom-type" {
Ok(Self)
} else {
Err(0.0)
}
}
}
#[component]
fn Blog(id: MyCustomType) -> Element {
rsx! {
h1 { "How to make: " }
p { "{id}" }
}
}
Author
|
Ok, I've just added an |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routablecreates types which derivePartialEq, but can also deriveEq. Clippy complains about this. This PR makes them deriveEqas well. If deriving onlyPartialEqis intentional let me know and I'll add an#[allow]instead.