Skip to content

Commit 53220f2

Browse files
committed
Minor code clean-up
Apply most clippy code improvement suggestions. Ignore the unnecessary_unwrap lint where non-beneficial (see rust-lang/rust-clippy#4530).
1 parent 7ddf5cc commit 53220f2

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/hexagon.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl FloatCoordinate {
180180
-self.q - self.r
181181
}
182182

183+
#[allow(clippy::many_single_char_names)]
183184
pub fn from_pixel(layout: &Layout, p: Point) -> Self {
184185
let o = &layout.orientation;
185186
let x = (p.0 - layout.origin.0) / layout.size.0;
@@ -462,7 +463,7 @@ impl<'de> Deserialize<'de> for Direction {
462463
where
463464
E: de::Error,
464465
{
465-
if value >= 0 && value <= 5 {
466+
if (0..6).contains(&value) {
466467
Ok(Direction::from(value as u8))
467468
} else {
468469
Err(E::custom(format!("direction out of range: {}", value)))
@@ -473,7 +474,7 @@ impl<'de> Deserialize<'de> for Direction {
473474
where
474475
E: de::Error,
475476
{
476-
if value <= 5 {
477+
if (0..6).contains(&value) {
477478
Ok(Direction::from(value as u8))
478479
} else {
479480
Err(E::custom(format!("direction out of range: {}", value)))

src/tile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl FromStr for Terrain {
514514
type Err = ParseTerrainError;
515515

516516
fn from_str(s: &str) -> Result<Self, Self::Err> {
517-
let idx = s.find('-').unwrap_or(s.len());
517+
let idx = s.find('-').unwrap_or_else(|| s.len());
518518
let surface = &s[0..idx];
519519

520520
let level = if let Some(val) = s.get(idx+1..) {

src/view/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl ExportView {
234234
// remove tile from todo list
235235
self.images.retain(|img| img.tile != *tile);
236236

237-
if self.images.len() == 0 {
237+
if self.images.is_empty() {
238238
debug!("export of all tile images is completed");
239239
let url = check!(self.canvas.to_data_url_with_type("image/png").ok());
240240
check!(self.anchor.set_attribute("href", &url).ok());

0 commit comments

Comments
 (0)