From 2994de6d0ff53b5f728e071f2b62343be34d1cd6 Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Sat, 31 Dec 2022 10:59:35 -0500 Subject: [PATCH] Changed return type of Layer::spatial_ref from `Result` to `Option`. Fixes #248. --- CHANGES.md | 6 ++++++ src/vector/layer.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 27874c5b..5f5ab631 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,12 @@ - Added prebuilt bindings for GDAL 3.6 (released 6 November 2022). + - + +- **Breaking**: `Layer::spatial_ref` returns `Option` instead of `Result`, thereby better reflecting the semantics documented in the [C++ API](https://gdal.org/doxygen/classOGRLayer.html#a75c06b4993f8eb76b569f37365cd19ab) + + - + ## 0.14 - Added new content to `README.md` and the root docs. diff --git a/src/vector/layer.rs b/src/vector/layer.rs index 7ceddee9..90065cd5 100644 --- a/src/vector/layer.rs +++ b/src/vector/layer.rs @@ -418,13 +418,16 @@ pub trait LayerAccess: Sized { /// Fetch the spatial reference system for this layer. /// + /// Returns `Some(SpatialRef)`, or `None` if one isn't defined. + /// /// Refer [OGR_L_GetSpatialRef](https://gdal.org/doxygen/classOGRLayer.html#a75c06b4993f8eb76b569f37365cd19ab) - fn spatial_ref(&self) -> Result { + fn spatial_ref(&self) -> Option { let c_obj = unsafe { gdal_sys::OGR_L_GetSpatialRef(self.c_layer()) }; if c_obj.is_null() { - return Err(_last_null_pointer_err("OGR_L_GetSpatialRef")); + None + } else { + unsafe { SpatialRef::from_c_obj(c_obj) }.ok() } - unsafe { SpatialRef::from_c_obj(c_obj) } } fn reset_feature_reading(&mut self) {