Skip to content

Commit

Permalink
Merge #353
Browse files Browse the repository at this point in the history
353: Fix clippy warning r=lnicola a=lnicola

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [ ] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

CC #352

Co-authored-by: Laurențiu Nicola <[email protected]>
  • Loading branch information
bors[bot] and lnicola authored Dec 15, 2022
2 parents 548cd33 + c81de40 commit 8cdf63e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn run() -> gdal::errors::Result<()> {
for field in defn.fields() {
ft.set_field(
&field.name(),
&match feature_a.field(&field.name())?.unwrap() {
&match feature_a.field(field.name())?.unwrap() {
// add one day to dates
FieldValue::DateValue(value) => {
println!("{} = {}", field.name(), value);
Expand Down
2 changes: 1 addition & 1 deletion gdal-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn add_docs_rs_helper(version: Option<&str>) {
}"#
.to_string()
};
std::fs::write(&out_path, docs_helper_code.as_bytes()).unwrap();
std::fs::write(out_path, docs_helper_code.as_bytes()).unwrap();
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
let callback_raw = CPLGetErrorHandlerUserData();
let callback: &mut Box<ErrorCallbackType> = &mut *(callback_raw as *mut Box<_>);

callback(error_type, error_num as i32, &error_msg);
callback(error_type, error_num, &error_msg);
}

// pin memory location of callback for sending its pointer to GDAL
Expand Down
19 changes: 7 additions & 12 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'a> RasterBand<'a> {
buffer: &mut [T],
e_resample_alg: Option<ResampleAlg>,
) -> Result<()> {
let pixels = (size.0 * size.1) as usize;
let pixels = size.0 * size.1;
assert_eq!(buffer.len(), pixels);

let resample_alg = e_resample_alg.unwrap_or(ResampleAlg::NearestNeighbour);
Expand Down Expand Up @@ -317,7 +317,7 @@ impl<'a> RasterBand<'a> {
size: (usize, usize),
e_resample_alg: Option<ResampleAlg>,
) -> Result<Buffer<T>> {
let pixels = (size.0 * size.1) as usize;
let pixels = size.0 * size.1;
let mut data: Vec<T> = Vec::with_capacity(pixels);

let resample_alg = e_resample_alg.unwrap_or(ResampleAlg::NearestNeighbour);
Expand Down Expand Up @@ -395,12 +395,7 @@ impl<'a> RasterBand<'a> {
/// Read the full band as a 'Buffer<T>', where `T` implements ['GdalType'].
pub fn read_band_as<T: Copy + GdalType>(&self) -> Result<Buffer<T>> {
let size = self.size();
self.read_as::<T>(
(0, 0),
(size.0 as usize, size.1 as usize),
(size.0 as usize, size.1 as usize),
None,
)
self.read_as::<T>((0, 0), (size.0, size.1), (size.0, size.1), None)
}

#[cfg(feature = "ndarray")]
Expand All @@ -414,7 +409,7 @@ impl<'a> RasterBand<'a> {
/// The Matrix shape is (rows, cols) and raster shape is (cols in x-axis, rows in y-axis).
pub fn read_block<T: Copy + GdalType>(&self, block_index: (usize, usize)) -> Result<Array2<T>> {
let size = self.block_size();
let pixels = (size.0 * size.1) as usize;
let pixels = size.0 * size.1;
let mut data: Vec<T> = Vec::with_capacity(pixels);

//let no_data:
Expand Down Expand Up @@ -486,7 +481,7 @@ impl<'a> RasterBand<'a> {
let no_data =
unsafe { gdal_sys::GDALGetRasterNoDataValue(self.c_rasterband, &mut pb_success) };
if pb_success == 1 {
return Some(no_data as f64);
return Some(no_data);
}
None
}
Expand Down Expand Up @@ -546,7 +541,7 @@ impl<'a> RasterBand<'a> {
let mut pb_success = 1;
let scale = unsafe { gdal_sys::GDALGetRasterScale(self.c_rasterband, &mut pb_success) };
if pb_success == 1 {
return Some(scale as f64);
return Some(scale);
}
None
}
Expand All @@ -565,7 +560,7 @@ impl<'a> RasterBand<'a> {
let mut pb_success = 1;
let offset = unsafe { gdal_sys::GDALGetRasterOffset(self.c_rasterband, &mut pb_success) };
if pb_success == 1 {
return Some(offset as f64);
return Some(offset);
}
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl TempFixture {
pub fn fixture(name: &str) -> Self {
let staging = Self::empty(name);
let source = Path::new("fixtures").join(name);
std::fs::copy(&source, &staging.temp_path).unwrap();
std::fs::copy(source, &staging.temp_path).unwrap();
staging
}

Expand Down
8 changes: 4 additions & 4 deletions src/vector/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> Feature<'a> {
}
OGRFieldType::OFTReal => {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsDouble(self.c_feature, field_id) };
Ok(Some(FieldValue::RealValue(rv as f64)))
Ok(Some(FieldValue::RealValue(rv)))
}
OGRFieldType::OFTRealList => {
let rv = unsafe {
Expand All @@ -124,7 +124,7 @@ impl<'a> Feature<'a> {
}
OGRFieldType::OFTInteger => {
let rv = unsafe { gdal_sys::OGR_F_GetFieldAsInteger(self.c_feature, field_id) };
Ok(Some(FieldValue::IntegerValue(rv as i32)))
Ok(Some(FieldValue::IntegerValue(rv)))
}
OGRFieldType::OFTIntegerList => {
let rv = unsafe {
Expand Down Expand Up @@ -426,12 +426,12 @@ impl<'a> Feature<'a> {
let tzoffset_secs = if tzflag == 0 || tzflag == 100 {
0
} else {
(tzflag as i32 - 100) * 15 * 60
(tzflag - 100) * 15 * 60
};
let rv = FixedOffset::east_opt(tzoffset_secs)
.ok_or_else(|| GdalError::DateError(tzoffset_secs.to_string()))?
.with_ymd_and_hms(
year as i32,
year,
month as u32,
day as u32,
hour as u32,
Expand Down
2 changes: 1 addition & 1 deletion src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Geometry {
let mut y: c_double = 0.;
let mut z: c_double = 0.;
unsafe { gdal_sys::OGR_G_GetPoint(self.c_geometry(), i, &mut x, &mut y, &mut z) };
(x as f64, y as f64, z as f64)
(x, y, z)
}

pub fn get_point_vec(&self) -> Vec<(f64, f64, f64)> {
Expand Down

0 comments on commit 8cdf63e

Please sign in to comment.