stac_io/
write.rs

1use crate::{Format, Result, Writeable};
2use std::path::Path;
3
4/// Writes a STAC value to a path.
5///
6/// The format will be inferred from the href's extension. If you want to
7/// specify the format, use [Format::write].
8///
9/// # Examples
10///
11/// ```no_run
12/// use stac::Item;
13///
14/// let item = Item::new("an-id");
15/// stac_io::write("an-id.json", item).unwrap();
16/// ```
17pub fn write<T: Writeable>(path: impl AsRef<Path>, value: T) -> Result<()> {
18    let path = path.as_ref();
19    let format = path
20        .to_str()
21        .and_then(Format::infer_from_href)
22        .unwrap_or_default();
23    format.write(path, value)
24}