From 3cdfc5dd00c5a39ff161f5d4536d96846ebb203e Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 30 Dec 2025 09:42:08 -0600 Subject: [PATCH 1/4] fix doc warnings --- src/deserialize/mod.rs | 5 ++--- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/deserialize/mod.rs b/src/deserialize/mod.rs index 50c9e05..f4888ad 100644 --- a/src/deserialize/mod.rs +++ b/src/deserialize/mod.rs @@ -1,8 +1,7 @@ //! This module deserialises to WKT using [`serde`]. //! //! You can deserialise to [`geo_types`] or any other implementor of [`TryFromWkt`], using -//! [`deserialize_wkt`]. Or you can store this crates internal primitives [`wkt`] -//! or [`Wkt`] in your struct fields. +//! [`deserialize_wkt`]. Alternatively, you can store this crate's [`Wkt`] in your struct fields. use crate::{TryFromWkt, Wkt, WktNum}; use serde::de::{Deserializer, Error, Visitor}; @@ -19,7 +18,7 @@ pub mod geo_types; /// Deserializes a WKT String into any type which implements `TryFromWkt`. /// /// This is useful when you have a struct which has a structured geometry field, (like a [`geo`](https://docs.rs/geo) or -/// [`geo-types`] geometry) stored as WKT. +/// [`geo-types`](https://docs.rs/geo-types) geometry) stored as WKT. /// #[cfg_attr(feature = "geo-types", doc = "```")] #[cfg_attr(not(feature = "geo-types"), doc = "```ignore")] diff --git a/src/lib.rs b/src/lib.rs index 4e2047b..bea6783 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ //! Conversions are available via the [`TryFromWkt`] and [`ToWkt`] traits, with implementations for //! [`geo_types`] and [`geo_traits`] primitives enabled by default. //! -//! For advanced usage, see the [`types`](crate::types) module for a list of internally used types. +//! For advanced usage, see the [`types`] module for a list of internally used types. //! //! This crate has optional `serde` integration for deserializing fields containing WKT. See //! [`deserialize`] for an example. From 70e08db881eb2bb5d02971e883e43783d39ccaff Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 30 Dec 2025 09:48:27 -0600 Subject: [PATCH 2/4] fixup doc cfg flag --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bea6783..5eed5eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ // The unstable `doc_auto_cfg` feature annotates documentation with any required cfg/features // needed for optional items. We set the `docsrs` config when building for docs.rs. To use it // in a local docs build, run: `cargo +nightly rustdoc --all-features -- --cfg docsrs` -#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] //! The `wkt` crate provides conversions to and from the [WKT (Well Known Text)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) //! geometry format. From 389993be2b2391f9f44a16bcc7658750656de132 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 30 Dec 2025 09:58:24 -0600 Subject: [PATCH 3/4] docs ci build --- .github/workflows/test.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf2b3b2..2c22700 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: name: Run tests jobs: - wkt: + test: name: wkt runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" @@ -28,3 +28,13 @@ jobs: - run: cargo clippy --all-features --all-targets -- -Dwarnings - run: cargo test --all-features - run: cargo test --no-default-features + doc: + name: Documentation + runs-on: ubuntu-latest + env: + RUSTDOCFLAGS: -Dwarnings + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@nightly + - uses: dtolnay/install@cargo-docs-rs + - run: cargo docs-rs From 6ca6e345dd391252799bab6e158c23e140e89487 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 30 Dec 2025 10:11:18 -0600 Subject: [PATCH 4/4] fix clippy warnings --- src/deserialize/mod.rs | 119 +++++++++-------------------------------- src/infer_type.rs | 2 +- src/to_wkt/mod.rs | 9 ++-- 3 files changed, 30 insertions(+), 100 deletions(-) diff --git a/src/deserialize/mod.rs b/src/deserialize/mod.rs index f4888ad..b4f3a02 100644 --- a/src/deserialize/mod.rs +++ b/src/deserialize/mod.rs @@ -143,35 +143,6 @@ where } } -struct GeometryVisitor { - _marker: PhantomData, -} - -impl Default for GeometryVisitor { - fn default() -> Self { - GeometryVisitor { - _marker: PhantomData, - } - } -} - -impl Visitor<'_> for GeometryVisitor -where - T: FromStr + Default + WktNum, -{ - type Value = Wkt; - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(formatter, "a valid WKT format") - } - fn visit_str(self, s: &str) -> Result - where - E: Error, - { - let wkt = Wkt::from_str(s).map_err(|e| serde::de::Error::custom(e))?; - Ok(wkt) - } -} - #[cfg(test)] mod tests { use super::*; @@ -184,71 +155,33 @@ mod tests { Deserializer, Error as _, IntoDeserializer, }; - mod wkt { - use super::*; - - #[test] - fn deserialize() { - let deserializer: StrDeserializer<'_, Error> = "POINT (10 20.1)".into_deserializer(); - let wkt = deserializer - .deserialize_any(WktVisitor::::default()) - .unwrap(); - assert!(matches!( - wkt, - Wkt::Point(Point { - coord: Some(Coord { - x: _, // floating-point types cannot be used in patterns - y: _, // floating-point types cannot be used in patterns - z: None, - m: None, - }), - dim: _dim, - }) - )); - } - - #[test] - fn deserialize_error() { - let deserializer: StrDeserializer<'_, Error> = "POINT (10 20.1A)".into_deserializer(); - let wkt = deserializer.deserialize_any(WktVisitor::::default()); - assert_eq!( - wkt.unwrap_err(), - Error::custom("Unable to parse input number as the desired output type") - ); - } + #[test] + fn deserialize() { + let deserializer: StrDeserializer<'_, Error> = "POINT (10 20.1)".into_deserializer(); + let wkt = deserializer + .deserialize_any(WktVisitor::::default()) + .unwrap(); + assert!(matches!( + wkt, + Wkt::Point(Point { + coord: Some(Coord { + x: _, // floating-point types cannot be used in patterns + y: _, // floating-point types cannot be used in patterns + z: None, + m: None, + }), + dim: _dim, + }) + )); } - mod geometry { - use super::*; - - #[test] - fn deserialize() { - let deserializer: StrDeserializer<'_, Error> = "POINT (42 3.14)".into_deserializer(); - let geometry = deserializer - .deserialize_any(GeometryVisitor::::default()) - .unwrap(); - assert!(matches!( - geometry, - Wkt::Point(Point { - coord: Some(Coord { - x: _, // floating-point types cannot be used in patterns - y: _, // floating-point types cannot be used in patterns - z: None, - m: None, - }), - dim: _dim, - }) - )); - } - - #[test] - fn deserialize_error() { - let deserializer: StrDeserializer<'_, Error> = "POINT (42 PI3.14)".into_deserializer(); - let geometry = deserializer.deserialize_any(GeometryVisitor::::default()); - assert_eq!( - geometry.unwrap_err(), - Error::custom("Expected a number for the Y coordinate") - ); - } + #[test] + fn deserialize_error() { + let deserializer: StrDeserializer<'_, Error> = "POINT (10 20.1A)".into_deserializer(); + let wkt = deserializer.deserialize_any(WktVisitor::::default()); + assert_eq!( + wkt.unwrap_err(), + Error::custom("Unable to parse input number as the desired output type") + ); } } diff --git a/src/infer_type.rs b/src/infer_type.rs index c9ef6ce..9797edc 100644 --- a/src/infer_type.rs +++ b/src/infer_type.rs @@ -106,7 +106,7 @@ pub fn infer_type(input: &str) -> Result<(GeometryType, Dimension), String> { } else if input.starts_with(GEOMETRYCOLLECTION) { Ok((GeometryType::GeometryCollection, dim)) } else { - return Err(format!("Unsupported WKT prefix {}", input)); + Err(format!("Unsupported WKT prefix {}", input)) } } } diff --git a/src/to_wkt/mod.rs b/src/to_wkt/mod.rs index 1f77375..4207bc7 100644 --- a/src/to_wkt/mod.rs +++ b/src/to_wkt/mod.rs @@ -33,9 +33,9 @@ impl WriterWrapper { (Error::FmtError(_), Some(io_err)) => io_err, (Error::FmtError(fmt_err), None) => { debug_assert!(false, "FmtError without setting an error on WriterWrapper"); - io::Error::new(io::ErrorKind::Other, fmt_err.to_string()) + io::Error::other(fmt_err.to_string()) } - (other, _) => io::Error::new(io::ErrorKind::Other, other.to_string()), + (other, _) => io::Error::other(other.to_string()), } } } @@ -108,10 +108,7 @@ mod tests { struct FailingWriter; impl io::Write for FailingWriter { fn write(&mut self, _buf: &[u8]) -> io::Result { - Err(io::Error::new( - io::ErrorKind::Other, - "FailingWriter always fails", - )) + Err(io::Error::other("FailingWriter always fails")) } fn flush(&mut self) -> io::Result<()> {