Skip to content

Commit 0c4cd15

Browse files
committed
fix(core): allow impl Into<Value> for geoparquet
1 parent 8b4e752 commit 0c4cd15

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

core/src/geoparquet.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ mod has_feature {
4343
///
4444
/// let item: Item = stac::read("examples/simple-item.json").unwrap();
4545
/// let mut cursor = Cursor::new(Vec::new());
46-
/// stac::geoparquet::to_writer(&mut cursor, item.into()).unwrap();
46+
/// stac::geoparquet::to_writer(&mut cursor, item).unwrap();
4747
/// ```
48-
pub fn to_writer<W>(writer: W, value: Value) -> Result<()>
48+
pub fn to_writer<W>(writer: W, value: impl Into<Value>) -> Result<()>
4949
where
5050
W: Write + Send,
5151
{
@@ -68,16 +68,17 @@ mod has_feature {
6868
/// let mut options = GeoParquetWriterOptions::default();
6969
/// let writer_properties = WriterProperties::builder().set_compression(Compression::SNAPPY).build();
7070
/// options.writer_properties = Some(writer_properties);
71-
/// stac::geoparquet::to_writer_with_options(&mut cursor, item.into(), &options).unwrap();
71+
/// stac::geoparquet::to_writer_with_options(&mut cursor, item, &options).unwrap();
7272
/// ```
7373
pub fn to_writer_with_options<W>(
7474
writer: W,
75-
value: Value,
75+
value: impl Into<Value>,
7676
options: &GeoParquetWriterOptions,
7777
) -> Result<()>
7878
where
7979
W: Write + Send,
8080
{
81+
let value = value.into();
8182
match value {
8283
Value::ItemCollection(item_collection) => {
8384
let table = crate::geoarrow::to_table(item_collection)?;
@@ -88,7 +89,7 @@ mod has_feature {
8889
)
8990
.map_err(Error::from)
9091
}
91-
Value::Item(item) => to_writer(writer, ItemCollection::from(vec![item.clone()]).into()),
92+
Value::Item(item) => to_writer(writer, ItemCollection::from(vec![item])),
9293
_ => Err(Error::IncorrectType {
9394
actual: value.type_name().to_string(),
9495
expected: "Item or ItemCollection".to_string(),
@@ -118,21 +119,21 @@ mod has_feature {
118119

119120
#[cfg(test)]
120121
mod tests {
121-
use crate::{Href, Item, ItemCollection};
122+
use crate::{Href, Item, ItemCollection, Value};
122123
use bytes::Bytes;
123124
use std::{fs::File, io::Cursor};
124125

125126
#[test]
126127
fn to_writer_catalog() {
127128
let mut cursor = Cursor::new(Vec::new());
128-
let catalog = crate::read("examples/catalog.json").unwrap();
129+
let catalog: Value = crate::read("examples/catalog.json").unwrap();
129130
let _ = super::to_writer(&mut cursor, catalog).unwrap_err();
130131
}
131132

132133
#[test]
133134
fn to_writer_collection() {
134135
let mut cursor = Cursor::new(Vec::new());
135-
let collection = crate::read("examples/collection.json").unwrap();
136+
let collection: Value = crate::read("examples/collection.json").unwrap();
136137
let _ = super::to_writer(&mut cursor, collection).unwrap_err();
137138
}
138139

@@ -141,13 +142,13 @@ mod has_feature {
141142
let mut cursor = Cursor::new(Vec::new());
142143
let item = crate::read("examples/simple-item.json").unwrap();
143144
let item_collection = ItemCollection::from(vec![item]);
144-
super::to_writer(&mut cursor, item_collection.into()).unwrap();
145+
super::to_writer(&mut cursor, item_collection).unwrap();
145146
}
146147

147148
#[test]
148149
fn to_writer_item() {
149150
let mut cursor = Cursor::new(Vec::new());
150-
let item = crate::read("examples/simple-item.json").unwrap();
151+
let item: Value = crate::read("examples/simple-item.json").unwrap();
151152
super::to_writer(&mut cursor, item).unwrap();
152153
}
153154

@@ -163,7 +164,7 @@ mod has_feature {
163164
let mut item: Item = crate::read("examples/simple-item.json").unwrap();
164165
item.clear_href();
165166
let mut cursor = Cursor::new(Vec::new());
166-
super::to_writer(&mut cursor, item.clone().into()).unwrap();
167+
super::to_writer(&mut cursor, item.clone()).unwrap();
167168
let bytes = Bytes::from(cursor.into_inner());
168169
let item_collection = super::from_reader(bytes).unwrap();
169170
assert_eq!(item_collection.items[0], item);

0 commit comments

Comments
 (0)