-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fixes #33
Fixes #33
Conversation
- iter unnecessary - the match is there to put value into v so make that clearer
comments include another alternative if based method.
generator/src/util.rs
Outdated
match (self.done, self.s.is_empty(), self.pending.is_empty()) { | ||
(true, _, _) => None, | ||
(_, true, _) => { | ||
self.done = true; | ||
Some("") | ||
} | ||
(_, _, false) => Some(std::mem::take(&mut self.pending)), | ||
_ => { | ||
for (i, b) in self.s.bytes().enumerate() { | ||
if b == b' ' || self.splitters.contains(&b) { | ||
let ret = &self.s[..i]; | ||
// dont include the space, but include everything else on the next step | ||
if b != b' ' { | ||
self.pending = &self.s[i..i + 1] | ||
} | ||
self.s = &self.s[i + 1..]; | ||
return Some(ret); | ||
} | ||
} | ||
self.s = &self.s[i + 1..]; | ||
return Some(ret); | ||
// trailing data | ||
self.done = true; | ||
Some(self.s) | ||
} | ||
} | ||
// trailing data | ||
self.done = true; | ||
Some(self.s) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is more readable than the existing code. Could you revert the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer to else
as well?
If i take them out the first part would look like this
if self.done {
return None;
}
if self.s.is_empty() {
self.done = true;
return Some("");
}
...
The reason I ask is that if-else with returns in them triggers some lints.
Of course if you'd rather keep them in, regardless, I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those sound like quite opinionated lints then. I'm usually fond of functional style, but this is a bit too much IMO.
This reverts commit 28974cb.
reverted and removed unnecessary if's |
Some of these deserve explanations :
c7c8f22
2479d5f
expect
rather than a nakedunwrap
. As explained above, this part is just simple file handling of a file with a well known format so it seem like more complex error handling is unnecessary.28974cb
return
break
continue
,else
statements can often safely be removed.