-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FromWkt trait for reading WKT without exposing the user to the interm…
…ediate representation. Note that this isn't a performance change. It's about (hopefully) making the library easier to use. This is a corollary to #89, but for reading WKT, rather than writing. As we discussed there, probably there is no reason for the user to care about the Wkt struct. Note that the intermediate representation is still used (for now!), but the user is no longer required to interact with it. The road is open though for having a direct translation from Wkt text to the geo-types (or whatever) represenation (see geozero for inspiration).
- Loading branch information
1 parent
4576ece
commit ed53073
Showing
5 changed files
with
152 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// Create geometries from WKT. | ||
/// | ||
/// A default implementation exists for [geo-types](../geo-types), or you can implement this trait | ||
/// for your own types. | ||
pub trait TryFromWkt<T>: Sized { | ||
type Error; | ||
|
||
/// # Examples | ||
#[cfg_attr(feature = "geo-types", doc = "```")] | ||
#[cfg_attr(not(feature = "geo-types"), doc = "```ignore")] | ||
/// // This example requires the geo-types feature (on by default). | ||
/// use wkt::TryFromWkt; | ||
/// use geo_types::Point; | ||
/// let point: Point<f64> = Point::try_from_wkt_str("POINT(10 20)").unwrap(); | ||
/// assert_eq!(point.y(), 20.0); | ||
/// ``` | ||
fn try_from_wkt_str(wkt_str: &str) -> Result<Self, Self::Error>; | ||
|
||
/// # Examples | ||
#[cfg_attr(feature = "geo-types", doc = "```")] | ||
#[cfg_attr(not(feature = "geo-types"), doc = "```ignore")] | ||
/// // This example requires the geo-types feature (on by default). | ||
/// use wkt::TryFromWkt; | ||
/// use geo_types::Point; | ||
/// | ||
/// let fake_file = "POINT(10 20)".as_bytes().to_vec(); | ||
/// let point: Point<f64> = Point::try_from_wkt_reader(&*fake_file).unwrap(); | ||
/// assert_eq!(point.y(), 20.0); | ||
/// ``` | ||
fn try_from_wkt_reader(wkt_reader: impl std::io::Read) -> Result<Self, Self::Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters