Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Impl/from geo types #88

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changes

## next release
### Changed
### Added
* impl `std::fmt::Display` for `Wkt`.
* impls of From for the different types in `geo_types` are added.
### Changed
* Trait ToWkt gets deprecated.

## 0.10.0 - 2022-02-24
### Changed
Expand Down
37 changes: 26 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,42 @@
//!
//! # Examples
//!
//! Parse a WKT string to a type:
//!
//! ```
//! use std::str::FromStr;
//! use wkt::Wkt;
//! let point: Wkt<f64> = Wkt::from_str("POINT(10 20)").unwrap();
//!
//! let point: Wkt<f64> = "POINT(10 20)".parse().unwrap();
//! ```
//!
//! ```ignore
//! // Convert to a geo_types primitive from a Wkt struct
//! use std::convert::TryInto;
//! Convert to a geo_types primitive from a Wkt struct:
//!
//! ```
//! use wkt::Wkt;
//! use geo_types::Point;
//! let point: Wkt<f64> = Wkt::from_str("POINT(10 20)").unwrap();
//! let g_point: geo_types::Point<f64> = (10., 20.).into();
// // We can attempt to directly convert the Wkt without having to access its items field
//!
//! let point: Wkt<f64> = "POINT(10 20)".parse().unwrap();
//! let converted: Point<f64> = point.try_into().unwrap();
//!
//! let g_point: geo_types::Point<f64> = (10., 20.).into();
//!
//! assert_eq!(g_point, converted);
//! ```
//!
//! Take a geo_types structure and get its WKT representation:
//!
//! ```
//! use wkt::Wkt;
//!
//! let g_point: geo_types::Point<f64> = (10., 20.).into();
//! let wkt_point: Wkt<f64> = g_point.into();
//!
//! assert_eq!(wkt_point.to_string(), "POINT(10 20)");
//!
//! // or use it in a format string
//! assert_eq!(format!("{wkt_point}"), "POINT(10 20)");
//! ```
//!
//! ## Direct Access to the `item` Field
//! If you wish to work directly with one of the WKT [`types`] you can match on the `item` field
//! ```
Expand Down Expand Up @@ -84,9 +102,6 @@ extern crate geo_types;

extern crate thiserror;

#[cfg(feature = "geo-types")]
pub use crate::towkt::ToWkt;

#[cfg(feature = "geo-types")]
pub mod conversion;

Expand Down
Loading