From 484a56e5d390d29a75a3ec98d687c34509f267e3 Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Mon, 7 Nov 2022 13:00:18 -0500 Subject: [PATCH 1/4] Disallow warnings in doctests. --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a1635793..24bea7e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,9 @@ #![crate_type = "lib"] // Enable `doc_cfg` features when `docsrs` is defined by docs.rs config #![cfg_attr(docsrs, feature(doc_cfg))] +#![doc(test( + attr(deny(warnings), allow(dead_code, unused_variables)) +))] //! # GDAL //! [GDAL](http://gdal.org/) is a translator and processing library for various raster and vector geospatial data formats. From 2bad1d2ac0c371a9bbfa4bb8411285f5f674654c Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Mon, 7 Nov 2022 13:00:34 -0500 Subject: [PATCH 2/4] Fix doctest warnings. --- src/dataset.rs | 10 +++++----- src/driver.rs | 43 ---------------------------------------- src/lib.rs | 2 +- src/raster/rasterband.rs | 9 ++++----- src/vector/mod.rs | 1 - 5 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/dataset.rs b/src/dataset.rs index 3c123443..9f5accda 100644 --- a/src/dataset.rs +++ b/src/dataset.rs @@ -637,8 +637,8 @@ impl Dataset { /// Create a new layer with an empty name, no spatial reference, and unknown geometry type: /// /// ``` - /// # use gdal::Driver; - /// # let driver = Driver::get_by_name("GPKG").unwrap(); + /// # use gdal::DriverManager; + /// # let driver = DriverManager::get_driver_by_name("GPKG").unwrap(); /// # let mut dataset = driver.create_vector_only("/vsimem/example.gpkg").unwrap(); /// let blank_layer = dataset.create_layer(Default::default()).unwrap(); /// ``` @@ -646,9 +646,9 @@ impl Dataset { /// Create a new named line string layer using WGS84: /// /// ``` - /// # use gdal::{Driver, LayerOptions}; + /// # use gdal::{DriverManager, LayerOptions}; /// # use gdal::spatial_ref::SpatialRef; - /// # let driver = Driver::get_by_name("GPKG").unwrap(); + /// # let driver = DriverManager::get_driver_by_name("GPKG").unwrap(); /// # let mut dataset = driver.create_vector_only("/vsimem/example.gpkg").unwrap(); /// let roads = dataset.create_layer(LayerOptions { /// name: "roads", @@ -806,7 +806,7 @@ impl Dataset { /// } /// # /// # fn main() -> gdal::errors::Result<()> { - /// # let driver = gdal::Driver::get_by_name("SQLite")?; + /// # let driver = gdal::DriverManager::get_driver_by_name("SQLite")?; /// # let mut dataset = driver.create_vector_only(":memory:")?; /// # create_point_grid(&mut dataset)?; /// # assert_eq!(dataset.layer(0)?.features().count(), 10000); diff --git a/src/driver.rs b/src/driver.rs index b8087b84..870c8538 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -43,22 +43,6 @@ pub struct Driver { impl Driver { /// Returns the driver with the given short name or [`Err`] if not found. - /// - /// See also: [`count`](Self::count), [`get`](Self::get) - /// - /// # Example - /// - /// ```rust, no_run - /// use gdal::Driver; - /// # fn main() -> gdal::errors::Result<()> { - /// let cog_driver = Driver::get_by_name("COG")?; - /// println!("{}", cog_driver.long_name()); - /// # Ok(()) - /// # } - /// ``` - /// ```text - /// Cloud optimized GeoTIFF generator - /// ``` #[deprecated(note = "Please use `DriverManager::get_driver_by_name()` instead")] pub fn get_by_name(name: &str) -> Result { DriverManager::get_driver_by_name(name) @@ -66,39 +50,12 @@ impl Driver { /// Returns the driver with the given index, which must be less than the value returned by /// `Driver::count()`. - /// - /// See also: [`count`](Self::count) - /// - /// # Example - /// - /// ```rust, no_run - /// use gdal::Driver; - /// # fn main() -> gdal::errors::Result<()> { - /// assert!(Driver::count() > 0); - /// let d = Driver::get(0)?; - /// println!("'{}' is '{}'", d.short_name(), d.long_name()); - /// # Ok(()) - /// # } - /// ``` - /// ```text - /// 'VRT' is 'Virtual Raster' - /// ``` #[deprecated(note = "Please use `DriverManager::get_driver()` instead")] pub fn get(index: usize) -> Result { DriverManager::get_driver(index) } /// Returns the number of registered drivers. - /// - /// # Example - /// - /// ```rust, no_run - /// use gdal::Driver; - /// println!("{} drivers are registered", Driver::count()); - /// ``` - /// ```text - /// 203 drivers are registered - /// ``` #[deprecated(note = "Please use `DriverManager::count()` instead")] pub fn count() -> usize { DriverManager::count() diff --git a/src/lib.rs b/src/lib.rs index 24bea7e6..58150355 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ //! but for the maximally impatient, here you go: //! //! ```rust, no_run -//! use gdal::{Dataset, Metadata}; +//! use gdal::Dataset; //! # fn main() -> gdal::errors::Result<()> { //! let ds = Dataset::open("fixtures/m_3607824_se_17_1_20160620_sub.tif")?; //! println!("This {} is in '{}' and has {} bands.", ds.driver().long_name(), ds.spatial_ref()?.name()?, ds.raster_count()); diff --git a/src/raster/rasterband.rs b/src/raster/rasterband.rs index 7ba1e246..8ca9dde0 100644 --- a/src/raster/rasterband.rs +++ b/src/raster/rasterband.rs @@ -1048,7 +1048,7 @@ impl Debug for ColorEntry { /// # Example /// /// ```rust, no_run -/// use gdal::{Dataset, Driver}; +/// use gdal::{Dataset, DriverManager}; /// use gdal::raster::{ColorEntry, ColorTable, PaletteInterpretation}; /// # fn main() -> gdal::errors::Result<()> { /// @@ -1056,7 +1056,7 @@ impl Debug for ColorEntry { /// let ds = Dataset::open("fixtures/labels.tif")?; /// /// // Create in-memory copy to mutate -/// let mem_driver = Driver::get_by_name("MEM")?; +/// let mem_driver = DriverManager::get_driver_by_name("MEM")?; /// let ds = ds.create_copy(&mem_driver, "", &[])?; /// let mut band = ds.rasterband(1)?; /// assert!(band.color_table().is_none()); @@ -1070,7 +1070,7 @@ impl Debug for ColorEntry { /// band.set_color_table(&ct); /// /// // Render a PNG -/// let png_driver = Driver::get_by_name("PNG")?; +/// let png_driver = DriverManager::get_driver_by_name("PNG")?; /// ds.create_copy(&png_driver, "/tmp/labels.png", &[])?; /// /// # Ok(()) @@ -1107,8 +1107,7 @@ impl<'a> ColorTable<'a> { /// # Example /// /// ```rust, no_run - /// use gdal::{Dataset, Driver}; - /// use gdal::raster::{ColorEntry, ColorTable, PaletteInterpretation}; + /// use gdal::raster::{ColorEntry, ColorTable}; /// # fn main() -> gdal::errors::Result<()> { /// // Create a 16 step blue to white color table. /// let ct = ColorTable::color_ramp( diff --git a/src/vector/mod.rs b/src/vector/mod.rs index 7753e898..d83e79fb 100644 --- a/src/vector/mod.rs +++ b/src/vector/mod.rs @@ -9,7 +9,6 @@ //! // The `LayerAccess` trait enables reading of vector specific fields from the `Dataset`. //! use gdal::vector::LayerAccess; //! # fn main() -> gdal::errors::Result<()> { -//! use gdal::errors::GdalError; //! use gdal::vector::geometry_type_to_name; //! let dataset = Dataset::open("fixtures/roads.geojson")?; //! println!("Dataset description: {}", dataset.description()?); From 87e54ab6fb67020dee8a120d5597a53fadc1dbb5 Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Mon, 7 Nov 2022 13:13:35 -0500 Subject: [PATCH 3/4] Added cargo alias for displaying compiler output during doctest build. --- .cargo/config.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..f63d5126 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[alias] +# Run doctests, displaying compiler output +dto = "test --doc -- --show-output" \ No newline at end of file From d4f01b37e2666e7aee963982ff1068387e3c1049 Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Mon, 7 Nov 2022 13:14:21 -0500 Subject: [PATCH 4/4] fmt --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 58150355..dd0139e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,7 @@ #![crate_type = "lib"] // Enable `doc_cfg` features when `docsrs` is defined by docs.rs config #![cfg_attr(docsrs, feature(doc_cfg))] -#![doc(test( - attr(deny(warnings), allow(dead_code, unused_variables)) -))] +#![doc(test(attr(deny(warnings), allow(dead_code, unused_variables))))] //! # GDAL //! [GDAL](http://gdal.org/) is a translator and processing library for various raster and vector geospatial data formats.