Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simplification: No longer return "impl Iterator" #619

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

Merged

Conversation

Copy link
Member

@phip1611 phip1611 commented Dec 30, 2022
edited
Loading

This commit addresses #616 and replaces three occurrences of impl Iterator with a specific type. I do not see a benefit in the impl Iterator design pattern in our code base. Using a specific, public type is simpler for end-users, as discussed in #616.

impl Something only makes sense, I think, in use-cases where users specify code, such as in actix-web:

async fn greet(req: HttpRequest) -> impl Responder {
 let name = req.match_info().get("name").unwrap_or("World");
 format!("Hello {}!", &name)
}

Or in situations where the return type is complex and nested with many generics.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

GabrielMajeri reacted with thumbs up emoji
@phip1611 phip1611 linked an issue Dec 30, 2022 that may be closed by this pull request
@phip1611 phip1611 self-assigned this Dec 30, 2022
@phip1611 phip1611 force-pushed the memory-map-interface-simplification branch from 05d2ddb to efe840b Compare December 30, 2022 10:35
@phip1611 phip1611 mentioned this pull request Dec 30, 2022
2 tasks
@phip1611 phip1611 force-pushed the memory-map-interface-simplification branch from efe840b to ad6c5a7 Compare December 30, 2022 10:44
Copy link
Member Author

What does @nicholasbishop think?

Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

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

lgtm. I only recently became aware that returning an impl SomeTrait can be kind of an API footgun, especially with a trait like Iterator where you often actually want to expose additional traits at the same time.

@nicholasbishop nicholasbishop merged commit 1c9f2ef into rust-osdev:main Dec 30, 2022
@phip1611 phip1611 deleted the memory-map-interface-simplification branch December 30, 2022 19:36
Copy link
Collaborator

I do not see a benefit in the impl Iterator design pattern in our code base. Using a specific, public type is simpler for end-users

Agreed. When I initially started using the impl trait pattern in the code, it was fairly recently stabilised, and it seemed pretty useful since it "simplified" the public API by hiding away irrelevant structures, which were only defined to implement some trait or another. I didn't realize at the time that there would be downsides to this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@nicholasbishop nicholasbishop nicholasbishop approved these changes

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Expose MemoryMapIter in API

AltStyle によって変換されたページ (->オリジナル) /