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

Switch to ryu for float to string #120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ num-traits = "0.2"
serde = { version = "1.0", default-features = false, optional = true }
thiserror = "1.0.23"
log = "0.4.17"
ryu = "1.0"

[dev-dependencies]
criterion = "0.5.1"
Expand Down
40 changes: 20 additions & 20 deletions src/geo_types_from_wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use crate::types::*;
use crate::{TryFromWkt, Wkt};
use crate::{TryFromWkt, Wkt, WktNum};

use std::any::type_name;
use std::convert::{TryFrom, TryInto};
Expand Down Expand Up @@ -48,7 +48,7 @@ macro_rules! try_from_wkt_impl {
($($type: ident),+) => {
$(
/// Fallibly convert this WKT primitive into this [`geo_types`] primitive
impl<T: CoordNum> TryFrom<Wkt<T>> for geo_types::$type<T> {
impl<T: CoordNum + WktNum> TryFrom<Wkt<T>> for geo_types::$type<T> {
type Error = Error;

fn try_from(wkt: Wkt<T>) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -84,7 +84,7 @@ try_from_wkt_impl!(
);

/// Fallibly convert this WKT primitive into this [`geo_types`] primitive
impl<T: CoordNum> TryFrom<Wkt<T>> for geo_types::GeometryCollection<T> {
impl<T: CoordNum + WktNum> TryFrom<Wkt<T>> for geo_types::GeometryCollection<T> {
type Error = Error;

fn try_from(wkt: Wkt<T>) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<T: CoordNum> TryFrom<Wkt<T>> for geo_types::GeometryCollection<T> {

impl<T> From<Coord<T>> for geo_types::Coord<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
/// Convert from a WKT Coordinate to a [`geo_types::Coordinate`]
fn from(coord: Coord<T>) -> geo_types::Coord<T> {
Expand All @@ -137,7 +137,7 @@ where

impl<T> TryFrom<Point<T>> for geo_types::Point<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
type Error = Error;

Expand All @@ -153,14 +153,14 @@ where
#[deprecated(since = "0.9.0", note = "use `geometry.try_into()` instead")]
pub fn try_into_geometry<T>(geometry: &Wkt<T>) -> Result<geo_types::Geometry<T>, Error>
where
T: CoordNum,
T: CoordNum + WktNum,
{
geometry.clone().try_into()
}

impl<'a, T> From<&'a LineString<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
fn from(line_string: &'a LineString<T>) -> Self {
Self::LineString(line_string.clone().into())
Expand All @@ -169,7 +169,7 @@ where

impl<T> From<LineString<T>> for geo_types::LineString<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
/// Convert from a WKT `LINESTRING` to a [`geo_types::LineString`]
fn from(line_string: LineString<T>) -> Self {
Expand All @@ -185,7 +185,7 @@ where

impl<'a, T> From<&'a MultiLineString<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
fn from(multi_line_string: &'a MultiLineString<T>) -> geo_types::Geometry<T> {
Self::MultiLineString(multi_line_string.clone().into())
Expand All @@ -194,7 +194,7 @@ where

impl<T> From<MultiLineString<T>> for geo_types::MultiLineString<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
/// Convert from a WKT `MULTILINESTRING` to a [`geo_types::MultiLineString`]
fn from(multi_line_string: MultiLineString<T>) -> geo_types::MultiLineString<T> {
Expand All @@ -210,7 +210,7 @@ where

impl<'a, T> From<&'a Polygon<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
fn from(polygon: &'a Polygon<T>) -> geo_types::Geometry<T> {
Self::Polygon(polygon.clone().into())
Expand All @@ -219,7 +219,7 @@ where

impl<T> From<Polygon<T>> for geo_types::Polygon<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
/// Convert from a WKT `POLYGON` to a [`geo_types::Polygon`]
fn from(polygon: Polygon<T>) -> Self {
Expand All @@ -233,7 +233,7 @@ where

impl<'a, T> TryFrom<&'a MultiPoint<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
type Error = Error;

Expand All @@ -244,7 +244,7 @@ where

impl<T> TryFrom<MultiPoint<T>> for geo_types::MultiPoint<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
type Error = Error;
/// Fallibly convert from a WKT `MULTIPOINT` to a [`geo_types::MultiPoint`]
Expand All @@ -261,7 +261,7 @@ where

impl<'a, T> From<&'a MultiPolygon<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
fn from(multi_polygon: &'a MultiPolygon<T>) -> Self {
Self::MultiPolygon(multi_polygon.clone().into())
Expand All @@ -270,7 +270,7 @@ where

impl<T> From<MultiPolygon<T>> for geo_types::MultiPolygon<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
/// Convert from a WKT `MULTIPOLYGON` to a [`geo_types::MultiPolygon`]
fn from(multi_polygon: MultiPolygon<T>) -> Self {
Expand All @@ -289,7 +289,7 @@ pub fn try_into_geometry_collection<T>(
geometry_collection: &GeometryCollection<T>,
) -> Result<geo_types::Geometry<T>, Error>
where
T: CoordNum,
T: CoordNum + WktNum,
{
Ok(geo_types::Geometry::GeometryCollection(
geometry_collection.clone().try_into()?,
Expand All @@ -298,7 +298,7 @@ where

impl<T> TryFrom<GeometryCollection<T>> for geo_types::GeometryCollection<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
type Error = Error;

Expand All @@ -315,7 +315,7 @@ where

impl<T> TryFrom<Wkt<T>> for geo_types::Geometry<T>
where
T: CoordNum,
T: CoordNum + WktNum,
{
type Error = Error;

Expand Down Expand Up @@ -348,7 +348,7 @@ where
macro_rules! try_from_wkt_impl {
($($type: ty),*$(,)?) => {
$(
impl<T: CoordNum + FromStr + Default> TryFromWkt<T> for $type {
impl<T: CoordNum + FromStr + Default + WktNum> TryFromWkt<T> for $type {
type Error = Error;
fn try_from_wkt_str(wkt_str: &str) -> Result<Self, Self::Error> {
let wkt = Wkt::from_str(wkt_str).map_err(|e| Error::InvalidWKT(e))?;
Expand Down
Loading
Loading