Skip to content

Commit

Permalink
Fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Feb 19, 2018
1 parent 76000c6 commit 17b485d
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 92 deletions.
6 changes: 3 additions & 3 deletions examples/read_write_ogr.rs
Expand Up @@ -23,7 +23,7 @@ fn run() -> Result<(), Error> {
for fd in &fields_defn {
let field_defn = FieldDefn::new(&fd.0, fd.1)?;
field_defn.set_width(fd.2);
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;
}

// Prepare the origin and destination spatial references objects:
Expand All @@ -34,7 +34,7 @@ fn run() -> Result<(), Error> {
let htransform = CoordTransform::new(&spatial_ref_src, &spatial_ref_dst)?;

// Get the definition to use on each feature:
let defn = Defn::from_layer(&lyr);
let defn = Defn::from_layer(lyr);

for feature_a in layer_a.features() {
// Get the original geometry:
Expand All @@ -49,7 +49,7 @@ fn run() -> Result<(), Error> {
ft.set_field(&fd.0, &feature_a.field(&fd.0)?)?;
}
// Add the feature to the layer:
ft.create(&lyr)?;
ft.create(lyr)?;
}

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions examples/write_ogr.rs
Expand Up @@ -15,26 +15,26 @@ fn example_1() -> Result<(), Error> {

let field_defn = FieldDefn::new("Name", OGRFieldType::OFTString)?;
field_defn.set_width(80);
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;

let field_defn = FieldDefn::new("Value", OGRFieldType::OFTReal)?;
field_defn.add_to_layer(&lyr)?;
field_defn.add_to_layer(lyr)?;

let defn = Defn::from_layer(&lyr);
let defn = Defn::from_layer(lyr);

// 1st feature:
let mut ft = Feature::new(&defn)?;
ft.set_geometry(Geometry::from_wkt("POINT (45.21 21.76)")?)?;
ft.set_field_string("Name", "Feature 1")?;
ft.set_field_double("Value", 45.78)?;
ft.create(&lyr)?;
ft.create(lyr)?;

// 2nd feature:
let mut ft = Feature::new(&defn)?;
ft.set_field_double("Value", 0.789)?;
ft.set_geometry(Geometry::from_wkt("POINT (46.50 22.50)")?)?;
ft.set_field_string("Name", "Feature 2")?;
ft.create(&lyr)?;
ft.create(lyr)?;

// Feature triggering an error due to a wrong field name:
let mut ft = Feature::new(&defn)?;
Expand All @@ -44,7 +44,7 @@ fn example_1() -> Result<(), Error> {
Ok(v) => v,
Err(err) => println!("{}", err),
};
ft.create(&lyr)?;
ft.create(lyr)?;

Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Expand Up @@ -20,7 +20,7 @@
//! assert_eq!(get_config_option("GDAL_CACHEMAX", "XXX").unwrap(), "XXX");
//! ```
//!
//! Refer to [GDAL ConfigOptions](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
//! Refer to [GDAL `ConfigOptions`](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
//! a full list of options.

use std::ffi::CString;
Expand All @@ -30,7 +30,7 @@ use errors::*;

/// Set a GDAL library configuration option
///
/// Refer to [GDAL ConfigOptions](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// Refer to [GDAL `ConfigOptions`](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// a full list of options.
///
pub fn set_config_option(key: &str, value: &str) -> Result<()> {
Expand All @@ -44,7 +44,7 @@ pub fn set_config_option(key: &str, value: &str) -> Result<()> {
///
/// If the config option specified by `key` is not found, the value passed in the `default` paramter is returned.
///
/// Refer to [GDAL ConfigOptions](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// Refer to [GDAL `ConfigOptions`](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// a full list of options.
pub fn get_config_option(key: &str, default: &str) -> Result<String> {
let c_key = CString::new(key.as_bytes())?;
Expand All @@ -55,7 +55,7 @@ pub fn get_config_option(key: &str, default: &str) -> Result<String> {

/// Clear the value of a GDAL library configuration option
///
/// Refer to [GDAL ConfigOptions](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// Refer to [GDAL `ConfigOptions`](https://trac.osgeo.org/gdal/wiki/ConfigOptions) for
/// a full list of options.
pub fn clear_config_option(key: &str) -> Result<()> {
let c_key = CString::new(key.as_bytes())?;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -13,7 +13,7 @@
//! for feature in layer.features() {
//! let highway_field = feature.field("highway").unwrap();
//! let geometry = feature.geometry();
//! println!("{} {}", highway_field.to_string().unwrap(), geometry.wkt().unwrap());
//! println!("{} {}", highway_field.into_string().unwrap(), geometry.wkt().unwrap());
//! }
//! ```

Expand Down
17 changes: 8 additions & 9 deletions src/raster/dataset.rs
Expand Up @@ -46,15 +46,14 @@ impl Dataset {
}

pub unsafe fn _with_c_ptr(c_dataset: GDALDatasetH) -> Dataset {
return Dataset{c_dataset: c_dataset};
Dataset { c_dataset: c_dataset }
}

pub unsafe fn _c_ptr(&self) -> GDALDatasetH {
return self.c_dataset;
self.c_dataset
}


pub fn rasterband<'a>(&'a self, band_index: isize) -> Result<RasterBand<'a>> {
pub fn rasterband(&self, band_index: isize) -> Result<RasterBand> {
unsafe {
let c_band = gdal_sys::GDALGetRasterBand(self.c_dataset, band_index as c_int);
if c_band.is_null() {
Expand All @@ -67,23 +66,23 @@ impl Dataset {
pub fn size(&self) -> (usize, usize) {
let size_x = unsafe { gdal_sys::GDALGetRasterXSize(self.c_dataset) } as usize;
let size_y = unsafe { gdal_sys::GDALGetRasterYSize(self.c_dataset) } as usize;
return (size_x, size_y);
(size_x, size_y)
}

pub fn driver(&self) -> Driver {
unsafe {
let c_driver = gdal_sys::GDALGetDatasetDriver(self.c_dataset);
return Driver::_with_c_ptr(c_driver);
};
Driver::_with_c_ptr(c_driver)
}
}

pub fn count(&self) -> isize {
return unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset) } as isize;
(unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset) }) as isize
}

pub fn projection(&self) -> String {
let rv = unsafe { gdal_sys::GDALGetProjectionRef(self.c_dataset) };
return _string(rv);
_string(rv)
}

pub fn set_projection(&self, projection: &str) -> Result<()>{
Expand Down
12 changes: 6 additions & 6 deletions src/raster/driver.rs
Expand Up @@ -40,21 +40,21 @@ impl Driver {
}

pub unsafe fn _with_c_ptr(c_driver: GDALDriverH) -> Driver {
return Driver{c_driver: c_driver};
Driver { c_driver: c_driver }
}

pub unsafe fn _c_ptr(&self) -> GDALDriverH {
return self.c_driver;
self.c_driver
}

pub fn short_name(&self) -> String {
let rv = unsafe { gdal_sys::GDALGetDriverShortName(self.c_driver) };
return _string(rv);
_string(rv)
}

pub fn long_name(&self) -> String {
let rv = unsafe { gdal_sys::GDALGetDriverLongName(self.c_driver) };
return _string(rv);
_string(rv)
}

pub fn create(
Expand Down Expand Up @@ -92,13 +92,13 @@ impl Driver {
if c_dataset.is_null() {
return Err(_last_null_pointer_err("GDALCreate").into());
};
Ok( unsafe { Dataset::_with_c_ptr(c_dataset) } )
Ok(unsafe { Dataset::_with_c_ptr(c_dataset) })
}
}

impl MajorObject for Driver {
unsafe fn gdal_object_ptr(&self) -> GDALMajorObjectH {
return self.c_driver;
self.c_driver
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/raster/rasterband.rs
Expand Up @@ -116,8 +116,7 @@ impl <'a> RasterBand<'a> {
}

pub fn band_type(&self) -> GDALDataType::Type {
let gdal_type = unsafe { gdal_sys::GDALGetRasterDataType(self.c_rasterband) };
gdal_type
unsafe { gdal_sys::GDALGetRasterDataType(self.c_rasterband) }
}

pub fn no_data_value(&self) ->Option<f64> {
Expand Down
4 changes: 2 additions & 2 deletions src/spatial_ref/srs.rs
Expand Up @@ -51,7 +51,7 @@ impl CoordTransform {
} else {
let err = _last_cpl_err(CPLErr::CE_Failure);
let msg = if let ErrorKind::CplError(_, _, msg) = err {
if msg.trim().len() == 0 {
if msg.trim().is_empty() {
None
} else {
Some(msg)
Expand Down Expand Up @@ -165,7 +165,7 @@ impl SpatialRef {
pub fn from_c_obj(c_obj: OGRSpatialReferenceH) -> Result<SpatialRef> {
let mut_c_obj = unsafe { gdal_sys::OSRClone(c_obj) };
if mut_c_obj.is_null() {
return Err(_last_null_pointer_err("OSRClone").into());
Err(_last_null_pointer_err("OSRClone").into())
} else {
Ok(SpatialRef(mut_c_obj))
}
Expand Down
4 changes: 2 additions & 2 deletions src/vector/dataset.rs
Expand Up @@ -54,13 +54,13 @@ impl Dataset {

/// Get number of layers.
pub fn count(&self) -> isize {
return unsafe { gdal_sys::OGR_DS_GetLayerCount(self.c_dataset) } as isize;
(unsafe { gdal_sys::OGR_DS_GetLayerCount(self.c_dataset) }) as isize
}

fn _child_layer(&mut self, c_layer: OGRLayerH) -> &Layer {
let layer = unsafe { Layer::_with_c_layer(c_layer) };
self.layers.push(layer);
return self.layers.last().unwrap();
self.layers.last().unwrap()
}

/// Get layer number `idx`.
Expand Down
20 changes: 10 additions & 10 deletions src/vector/defn.rs
Expand Up @@ -16,36 +16,36 @@ pub struct Defn {

impl Defn {
pub unsafe fn _with_c_defn(c_defn: OGRFeatureDefnH) -> Defn {
Defn{c_defn: c_defn}
Defn { c_defn: c_defn }
}

pub unsafe fn c_defn(&self) -> OGRFeatureDefnH { self.c_defn }

/// Iterate over the field schema of this layer.
pub fn fields(&self) -> FieldIterator {
let total = unsafe { gdal_sys::OGR_FD_GetFieldCount(self.c_defn) } as isize;
return FieldIterator{
FieldIterator{
defn: self,
c_feature_defn: self.c_defn,
next_id: 0,
total: total
};
}
}

/// Iterate over the geometry field schema of this layer.
pub fn geom_fields(&self) -> GeomFieldIterator {
let total = unsafe { gdal_sys::OGR_FD_GetGeomFieldCount(self.c_defn) } as isize;
return GeomFieldIterator{
GeomFieldIterator {
defn: self,
c_feature_defn: self.c_defn,
next_id: 0,
total: total
};
}
}

pub fn from_layer(lyr: &Layer) -> Defn {
let c_defn = unsafe { gdal_sys::OGR_L_GetLayerDefn(lyr.c_layer())};
Defn {c_defn: c_defn}
Defn { c_defn: c_defn }
}
}

Expand All @@ -72,7 +72,7 @@ impl<'a> Iterator for FieldIterator<'a> {
) }
};
self.next_id += 1;
return Some(field);
Some(field)
}
}

Expand All @@ -85,7 +85,7 @@ impl<'a> Field<'a> {
/// Get the name of this field.
pub fn name(&'a self) -> String {
let rv = unsafe { gdal_sys::OGR_Fld_GetNameRef(self.c_field_defn) };
return _string(rv);
_string(rv)
}

pub fn field_type(&'a self) -> OGRFieldType::Type {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<'a> Iterator for GeomFieldIterator<'a> {
) }
};
self.next_id += 1;
return Some(field);
Some(field)
}
}

Expand All @@ -138,7 +138,7 @@ impl<'a> GeomField<'a> {
/// Get the name of this field.
pub fn name(&'a self) -> String {
let rv = unsafe { gdal_sys::OGR_GFld_GetNameRef(self.c_field_defn) };
return _string(rv);
_string(rv)
}

pub fn field_type(&'a self) -> WkbType {
Expand Down

0 comments on commit 17b485d

Please sign in to comment.