Skip to content

Commit

Permalink
fix: clean up clippies
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 8, 2024
1 parent 7ad6432 commit 3cdf4e7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) struct CompressedPointReader<Decompressor> {
#[cfg(not(feature = "laz-parallel"))]
impl<R: Read + Seek + Send> CompressedPointReader<laz::LasZipDecompressor<'_, R>> {
pub(crate) fn new(source: R, header: Header) -> Result<Self> {
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)?,
};
Expand All @@ -59,7 +59,7 @@ impl<R: Read + Seek + Send> CompressedPointReader<laz::LasZipDecompressor<'_, R>
#[cfg(feature = "laz-parallel")]
impl<R: Read + Seek + Send> CompressedPointReader<laz::ParLasZipDecompressor<R>> {
pub(crate) fn new(source: R, header: Header) -> Result<Self> {
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)?,
};
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum Error {

/// Wrapper around `las::writer::Error`.
#[error(transparent)]
Writer(#[from] writer::Error),
Writer(#[from] Box<writer::Error>),

/// Wrapper around `las::vlr::Error`.
#[error(transparent)]
Expand Down
9 changes: 2 additions & 7 deletions src/gps_time_type.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -43,9 +44,3 @@ impl From<u16> for GpsTimeType {
}
}
}

impl Default for GpsTimeType {
fn default() -> GpsTimeType {
GpsTimeType::Week
}
}
2 changes: 1 addition & 1 deletion src/header/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 2 additions & 7 deletions src/point/classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -118,9 +119,3 @@ impl From<Classification> for u8 {
}
}
}

impl Default for Classification {
fn default() -> Classification {
Classification::CreatedNeverClassified
}
}
9 changes: 2 additions & 7 deletions src/point/scan_direction.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 2 additions & 5 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ pub enum Error {
}

#[inline]
pub(crate) fn read_point_from<R: std::io::Read>(
mut source: &mut R,
header: &Header,
) -> Result<Point> {
let point = raw::Point::read_from(&mut source, header.point_format())
pub(crate) fn read_point_from<R: std::io::Read>(source: &mut R, header: &Header) -> Result<Point> {
let point = raw::Point::read_from(source, header.point_format())
.map(|raw_point| Point::new(raw_point, header.transforms()));
point
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
}

Expand Down Expand Up @@ -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(),
Expand Down
12 changes: 6 additions & 6 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<W: 'static + std::io::Write + Seek + Debug + Send> Writer<W> {
/// let writer = Writer::new(Cursor::new(Vec::new()), Default::default());
/// ```
pub fn new(mut dest: W, mut header: Header) -> Result<Self> {
let start = dest.seek(SeekFrom::Current(0))?;
let start = dest.stream_position()?;
header.clear();

#[cfg(feature = "laz")]
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<W: 'static + std::io::Write + Seek + Debug + Send> Writer<W> {
/// ```
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()?;
Expand All @@ -295,7 +295,7 @@ impl<W: 'static + std::io::Write + Seek + Debug + Send> Writer<W> {
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()
Expand All @@ -314,13 +314,13 @@ impl<W: 'static + std::io::Write + Seek + Debug + Send> Write for Writer<W> {
/// 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)
Expand Down

0 comments on commit 3cdf4e7

Please sign in to comment.