Skip to content

Example of how TryFrom could be implemented to be more flexible#78

Merged
MusicalNinjaDad merged 10 commits into
mainfrom
ViaIterator
Apr 16, 2026
Merged

Example of how TryFrom could be implemented to be more flexible#78
MusicalNinjaDad merged 10 commits into
mainfrom
ViaIterator

Conversation

@MusicalNinjaDad

Copy link
Copy Markdown
Owner

No description provided.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In ThirdWord::try_from2, split_whitespace().nth(3) returns the fourth word rather than the third; if you intend ThirdWord to represent the third word as the name and assertions suggest, this should be nth(2).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ThirdWord::try_from2`, `split_whitespace().nth(3)` returns the fourth word rather than the third; if you intend `ThirdWord` to represent the third word as the name and assertions suggest, this should be `nth(2)`.

## Individual Comments

### Comment 1
<location path="examples/TryFrom2.rs" line_range="107" />
<code_context>
+    fn try_from2(input: &str) -> Self::Return {
+        input
+            .split_whitespace()
+            .nth(3)
+            .map(|s| ThirdWord(s.to_string()))
+    }
</code_context>
<issue_to_address>
**issue (bug_risk):** Index passed to `nth` returns the fourth word rather than the third, causing the main assertion to be incorrect.

`.nth(3)` is zero-based and returns the fourth word, so this would yield "words" rather than the intended third word "of". Use `.nth(2)` to match the type’s intent and the test expectations.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread examples/TryFrom2.rs Outdated
@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) April 16, 2026 14:44
@MusicalNinjaDad MusicalNinjaDad merged commit 0f1344c into main Apr 16, 2026
18 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the ViaIterator branch April 16, 2026 14:44
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.

1 participant