Skip to content

Commit

Permalink
DerefMut for ResultSet
Browse files Browse the repository at this point in the history
  • Loading branch information
jdroenner committed Apr 25, 2021
1 parent 3fe326a commit 52951a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl Dataset {
///
/// let ds = Dataset::open(Path::new("fixtures/roads.geojson")).unwrap();
/// let query = "SELECT kind, is_bridge, highway FROM roads WHERE highway = 'pedestrian'";
/// let result_set = ds.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
/// let mut result_set = ds.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
///
/// assert_eq!(10, result_set.feature_count());
///
Expand Down
8 changes: 7 additions & 1 deletion src/vector/sql.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::Deref;
use std::ops::{Deref, DerefMut};

use gdal_sys::GDALDatasetH;

Expand All @@ -21,6 +21,12 @@ impl<'a> Deref for ResultSet<'a> {
}
}

impl<'a> DerefMut for ResultSet<'a> {
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
&mut self.layer
}
}

impl<'a> Drop for ResultSet<'a> {
fn drop(&mut self) {
unsafe { gdal_sys::GDALDatasetReleaseResultSet(self.dataset, self.layer.c_layer()) };
Expand Down
2 changes: 1 addition & 1 deletion src/vector/vector_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn test_layer_spatial_ref() {

#[test]
fn test_layer_capabilities() {
let mut ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let layer = ds.layer(0).unwrap();

assert!(!layer.has_capability(OLCFastSpatialFilter));
Expand Down
8 changes: 4 additions & 4 deletions src/vector/vector_tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
fn test_sql() {
let ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let query = "SELECT kind, is_bridge, highway FROM roads WHERE highway = 'pedestrian'";
let result_set = ds
let mut result_set = ds
.execute_sql(query, None, sql::Dialect::DEFAULT)
.unwrap()
.unwrap();
Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_sql_with_spatial_filter() {
let query = "SELECT * FROM roads WHERE highway = 'pedestrian'";
let ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let bbox = Geometry::bbox(26.1017, 44.4297, 26.1025, 44.4303).unwrap();
let result_set = ds
let mut result_set = ds
.execute_sql(query, Some(&bbox), sql::Dialect::DEFAULT)
.unwrap()
.unwrap();
Expand Down Expand Up @@ -77,7 +77,7 @@ fn test_sql_with_dialect() {
let query = "SELECT * FROM roads WHERE highway = 'pedestrian' and NumPoints(GEOMETRY) = 3";
let ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let bbox = Geometry::bbox(26.1017, 44.4297, 26.1025, 44.4303).unwrap();
let result_set = ds
let mut result_set = ds
.execute_sql(query, Some(&bbox), sql::Dialect::SQLITE)
.unwrap()
.unwrap();
Expand All @@ -99,7 +99,7 @@ fn test_sql_with_dialect() {
fn test_sql_empty_result() {
let ds = Dataset::open(fixture!("roads.geojson")).unwrap();
let query = "SELECT kind, is_bridge, highway FROM roads WHERE highway = 'jazz hands 👐'";
let result_set = ds
let mut result_set = ds
.execute_sql(query, None, sql::Dialect::DEFAULT)
.unwrap()
.unwrap();
Expand Down

0 comments on commit 52951a1

Please sign in to comment.