pub enum Format {
Json(bool),
NdJson,
}
Expand description
The format of STAC data.
Variants§
Json(bool)
JSON data (the default).
If true
, the data will be pretty-printed on write.
NdJson
Newline-delimited JSON.
Implementations§
Source§impl Format
impl Format
Sourcepub fn infer_from_href(href: &str) -> Option<Format>
pub fn infer_from_href(href: &str) -> Option<Format>
Infer the format from a file extension.
§Examples
use stac_io::Format;
assert_eq!(Format::Json(false), Format::infer_from_href("item.json").unwrap());
Sourcepub fn extension(&self) -> &'static str
pub fn extension(&self) -> &'static str
Returns this format’s file extension.
§Examples
use stac_io::Format;
assert_eq!(Format::json().extension(), "json");
assert_eq!(Format::ndjson().extension(), "ndjson");
#[cfg(feature = "geoparquet")]
assert_eq!(Format::geoparquet().extension(), "parquet");
Sourcepub fn read<T: Readable + SelfHref>(&self, href: impl ToString) -> Result<T>
pub fn read<T: Readable + SelfHref>(&self, href: impl ToString) -> Result<T>
Reads a STAC object from an href in this format.
§Examples
use stac::Item;
use stac_io::Format;
let item: Item = Format::json().read("examples/simple-item.json").unwrap();
Sourcepub fn from_path<T: Readable + SelfHref>(
&self,
path: impl AsRef<Path>,
) -> Result<T>
pub fn from_path<T: Readable + SelfHref>( &self, path: impl AsRef<Path>, ) -> Result<T>
Reads a local file in the given format.
§Examples
use stac::Item;
use stac_io::Format;
let item: Item = Format::json().from_path("examples/simple-item.json").unwrap();
Sourcepub fn from_bytes<T: Readable>(&self, bytes: impl Into<Bytes>) -> Result<T>
pub fn from_bytes<T: Readable>(&self, bytes: impl Into<Bytes>) -> Result<T>
Reads a STAC object from some bytes.
§Examples
use stac::Item;
use stac_io::Format;
use std::{io::Read, fs::File};
let mut buf = Vec::new();
File::open("examples/simple-item.json").unwrap().read_to_end(&mut buf).unwrap();
let item: Item = Format::json().from_bytes(buf).unwrap();
Sourcepub fn write<T: Writeable>(
&self,
path: impl AsRef<Path>,
value: T,
) -> Result<()>
pub fn write<T: Writeable>( &self, path: impl AsRef<Path>, value: T, ) -> Result<()>
Writes a STAC value to the provided path.
§Examples
use stac::Item;
use stac_io::Format;
Format::json().write("an-id.json", Item::new("an-id")).unwrap();
Trait Implementations§
impl Copy for Format
impl StructuralPartialEq for Format
Auto Trait Implementations§
impl Freeze for Format
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnwindSafe for Format
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more