Skip to content

Commit

Permalink
Minor code clean-up
Browse files Browse the repository at this point in the history
Apply most clippy code improvement suggestions. Ignore the
unnecessary_unwrap lint where non-beneficial (see rust-lang/rust-clippy#4530).
  • Loading branch information
t-rapp committed Apr 22, 2021
1 parent 7ddf5cc commit 53220f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/hexagon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl FloatCoordinate {
-self.q - self.r
}

#[allow(clippy::many_single_char_names)]
pub fn from_pixel(layout: &Layout, p: Point) -> Self {
let o = &layout.orientation;
let x = (p.0 - layout.origin.0) / layout.size.0;
Expand Down Expand Up @@ -462,7 +463,7 @@ impl<'de> Deserialize<'de> for Direction {
where
E: de::Error,
{
if value >= 0 && value <= 5 {
if (0..6).contains(&value) {
Ok(Direction::from(value as u8))
} else {
Err(E::custom(format!("direction out of range: {}", value)))
Expand All @@ -473,7 +474,7 @@ impl<'de> Deserialize<'de> for Direction {
where
E: de::Error,
{
if value <= 5 {
if (0..6).contains(&value) {
Ok(Direction::from(value as u8))
} else {
Err(E::custom(format!("direction out of range: {}", value)))
Expand Down
2 changes: 1 addition & 1 deletion src/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl FromStr for Terrain {
type Err = ParseTerrainError;

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

let level = if let Some(val) = s.get(idx+1..) {
Expand Down
2 changes: 1 addition & 1 deletion src/view/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl ExportView {
// remove tile from todo list
self.images.retain(|img| img.tile != *tile);

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

0 comments on commit 53220f2

Please sign in to comment.