diff --git a/src/compression/mod.rs b/src/compression/mod.rs index 6bd042fc..1cc1dc19 100644 --- a/src/compression/mod.rs +++ b/src/compression/mod.rs @@ -41,7 +41,7 @@ pub(crate) struct CompressedPointReader { #[cfg(not(feature = "laz-parallel"))] impl CompressedPointReader> { pub(crate) fn new(source: R, header: Header) -> Result { - let laszip_vlr = match header.vlrs().iter().find(|vlr| is_laszip_vlr(*vlr)) { + let laszip_vlr = match header.vlrs().iter().find(|vlr| is_laszip_vlr(vlr)) { None => return Err(Error::LasZipVlrNotFound), Some(vlr) => LazVlr::from_buffer(&vlr.data)?, }; @@ -59,7 +59,7 @@ impl CompressedPointReader #[cfg(feature = "laz-parallel")] impl CompressedPointReader> { pub(crate) fn new(source: R, header: Header) -> Result { - let laszip_vlr = match header.vlrs().iter().find(|vlr| is_laszip_vlr(*vlr)) { + let laszip_vlr = match header.vlrs().iter().find(|vlr| is_laszip_vlr(vlr)) { None => return Err(Error::LasZipVlrNotFound), Some(vlr) => LazVlr::from_buffer(&vlr.data)?, }; @@ -93,7 +93,7 @@ where self.last_point_idx += 1; let res = self .decompressor - .decompress_one(&mut self.decompressor_output.get_mut()); + .decompress_one(self.decompressor_output.get_mut()); if let Err(e) = res { Some(Err(e.into())) } else { diff --git a/src/error.rs b/src/error.rs index 8c6f62d7..3dea48ee 100644 --- a/src/error.rs +++ b/src/error.rs @@ -60,7 +60,7 @@ pub enum Error { /// Wrapper around `las::writer::Error`. #[error(transparent)] - Writer(#[from] writer::Error), + Writer(#[from] Box), /// Wrapper around `las::vlr::Error`. #[error(transparent)] diff --git a/src/gps_time_type.rs b/src/gps_time_type.rs index 017dec23..aa3d7164 100644 --- a/src/gps_time_type.rs +++ b/src/gps_time_type.rs @@ -1,7 +1,8 @@ /// The meaning of GPS time in the point records. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] pub enum GpsTimeType { /// GPS Week Time (the same as previous versions of LAS). + #[default] Week, /// Standard GPS Time minus 1e9. Standard, @@ -43,9 +44,3 @@ impl From for GpsTimeType { } } } - -impl Default for GpsTimeType { - fn default() -> GpsTimeType { - GpsTimeType::Week - } -} diff --git a/src/header/builder.rs b/src/header/builder.rs index 1a4f4934..d00d9627 100644 --- a/src/header/builder.rs +++ b/src/header/builder.rs @@ -91,7 +91,7 @@ impl Builder { raw_header .large_file .map(|f| number_of_points_hash_map(&f.number_of_points_by_return)) - .unwrap_or_else(HashMap::new) + .unwrap_or_default() }; let mut point_format = Format::new(raw_header.point_data_record_format)?; let n = point_format.len(); diff --git a/src/point/classification.rs b/src/point/classification.rs index 2c9814b9..6185bdfc 100644 --- a/src/point/classification.rs +++ b/src/point/classification.rs @@ -29,9 +29,10 @@ use crate::Result; /// use las::point::Classification; /// assert!(Classification::new(12).is_err()); /// ``` -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] #[allow(missing_docs)] pub enum Classification { + #[default] CreatedNeverClassified, Unclassified, Ground, @@ -118,9 +119,3 @@ impl From for u8 { } } } - -impl Default for Classification { - fn default() -> Classification { - Classification::CreatedNeverClassified - } -} diff --git a/src/point/scan_direction.rs b/src/point/scan_direction.rs index 67bdc3b2..bb0e7d4d 100644 --- a/src/point/scan_direction.rs +++ b/src/point/scan_direction.rs @@ -1,14 +1,9 @@ /// The direction at which the scanner mirror was traveling at the time of pulse output. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] pub enum ScanDirection { /// The scan is moving from the right to the left. + #[default] RightToLeft, /// The scan is moving from the left to the right. LeftToRight, } - -impl Default for ScanDirection { - fn default() -> ScanDirection { - ScanDirection::RightToLeft - } -} diff --git a/src/reader.rs b/src/reader.rs index e8900f54..f18c8ac3 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -65,11 +65,8 @@ pub enum Error { } #[inline] -pub(crate) fn read_point_from( - mut source: &mut R, - header: &Header, -) -> Result { - let point = raw::Point::read_from(&mut source, header.point_format()) +pub(crate) fn read_point_from(source: &mut R, header: &Header) -> Result { + let point = raw::Point::read_from(source, header.point_format()) .map(|raw_point| Point::new(raw_point, header.transforms())); point } diff --git a/src/utils.rs b/src/utils.rs index 19441922..4f0a0303 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,6 +8,7 @@ pub(crate) trait AsLasStr { } pub(crate) trait FromLasStr { + #[allow(clippy::wrong_self_convention)] fn from_las_str(&mut self, s: &str) -> Result<()>; } @@ -47,7 +48,7 @@ impl AsLasStr for &'_ [u8] { impl FromLasStr for &'_ mut [u8] { fn from_las_str(&mut self, s: &str) -> Result<()> { - if self.len() < s.bytes().count() { + if self.len() < s.len() { return Err(Error::StringTooLong { string: s.to_string(), len: self.len(), diff --git a/src/writer.rs b/src/writer.rs index e495b507..8e77c821 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -224,7 +224,7 @@ impl Writer { /// let writer = Writer::new(Cursor::new(Vec::new()), Default::default()); /// ``` pub fn new(mut dest: W, mut header: Header) -> Result { - let start = dest.seek(SeekFrom::Current(0))?; + let start = dest.stream_position()?; header.clear(); #[cfg(feature = "laz")] @@ -268,7 +268,7 @@ impl Writer { /// ``` pub fn close(&mut self) -> Result<()> { if self.closed { - return Err(Error::Closed.into()); + return Err(Box::new(Error::Closed).into()); } self.point_writer.done()?; @@ -295,7 +295,7 @@ impl Writer { self.header() .clone() .into_raw() - .and_then(|raw_header| raw_header.write_to(&mut self.point_writer.get_mut()))?; + .and_then(|raw_header| raw_header.write_to(self.point_writer.get_mut()))?; let _ = self .point_writer .get_mut() @@ -314,13 +314,13 @@ impl Write for Writer { /// Writes a point. fn write(&mut self, point: Point) -> Result<()> { if self.closed { - return Err(Error::Closed.into()); + return Err(Box::new(Error::Closed).into()); } if !point.matches(self.header().point_format()) { - return Err(Error::PointAttributes { + return Err(Box::new(Error::PointAttributes { format: *self.header().point_format(), point, - } + }) .into()); } self.point_writer.write_next(point)