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

Add TryFrom impls for JsonObject and JsonValue #120

Merged
merged 2 commits into from
Nov 16, 2019

Conversation

avandesa
Copy link
Contributor

For each GeoJson type, an impl TryFrom<JsonObject> and impl TryFrom<JsonValue> is added, and the analagous from_json_object and
from_json_value functions are converted to use the new traits.

This makes it possible to simplify the instantiation of GeoJson types
like this:

let feature: Feature = json!({
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
    },
    "properties": null,
}).try_into().unwrap();

impls are added for:

  • GeoJson
  • Geometry
  • Feature, and
  • FeatureCollection.

API stability is maintained - the only change is that the
from_json_object methods take JsonObject instead of
mut JsonObject, but this should not break anything.

Tests are added where appropriate.

This commit expands on #119.

For each GeoJson type, an `impl TryFrom<JsonObject>` and `impl
TryFrom<JsonValue>` is added, and the analagous `from_json_object` and
`from_json_value` functions are converted to use the new traits.

This makes it possible to simplify the instantiation of GeoJson types
like this:

```rust
let feature: Feature = json!({
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
    },
    "properties": null,
}).try_into().unwrap();
```

impls are added for:

* `GeoJson`
* `Geometry`
* `Feature`, and
* `FeatureCollection`.

API stability is maintained - the only change is that the
`from_json_object` methods take `JsonObject` instead of
`mut JsonObject`, but this should not break anything.

Tests are added where appropriate.
I'd changed this function for geometry objects, but not
features/collections. This makes it consistent.
Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea, thanks for the pull request!

@frewsxcv
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Nov 16, 2019
120: Add `TryFrom` impls for JsonObject and JsonValue r=frewsxcv a=avandesa

For each GeoJson type, an `impl TryFrom<JsonObject>` and `impl
TryFrom<JsonValue>` is added, and the analagous `from_json_object` and
`from_json_value` functions are converted to use the new traits.

This makes it possible to simplify the instantiation of GeoJson types
like this:

```rust
let feature: Feature = json!({
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
    },
    "properties": null,
}).try_into().unwrap();
```

impls are added for:

* `GeoJson`
* `Geometry`
* `Feature`, and
* `FeatureCollection`.

API stability is maintained - the only change is that the
`from_json_object` methods take `JsonObject` instead of
`mut JsonObject`, but this should not break anything.

Tests are added where appropriate.

This commit expands on #119.

Co-authored-by: Alex van de Sandt <[email protected]>
@bors
Copy link
Contributor

bors bot commented Nov 16, 2019

Build succeeded

@bors bors bot merged commit f874b94 into georust:master Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants