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

Remove manual map implementation in MaybeMath #161

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,20 @@ impl MaybeMath<Option<f32>, Option<f32>> for Option<f32> {
}

impl MaybeMath<f32, Option<f32>> for Option<f32> {
// The logic here is subtle and critical;
// explicit match statements make it more clear what's going on
#[allow(clippy::manual_map)]
fn maybe_min(self, rhs: f32) -> Option<f32> {
match self {
Some(val) => Some(val.min(rhs)),
None => None,
}
self.map(|val| val.min(rhs))
}

#[allow(clippy::manual_map)]
fn maybe_max(self, rhs: f32) -> Option<f32> {
match self {
Some(val) => Some(val.max(rhs)),
None => None,
}
self.map(|val| val.max(rhs))
}

#[allow(clippy::manual_map)]
fn maybe_add(self, rhs: f32) -> Option<f32> {
match self {
Some(val) => Some(val + rhs),
None => None,
}
self.map(|val| val + rhs)
}

#[allow(clippy::manual_map)]
fn maybe_sub(self, rhs: f32) -> Option<f32> {
match self {
Some(val) => Some(val - rhs),
None => None,
}
self.map(|val| val - rhs)
}
}

Expand Down