pub enum Format {
Json(bool),
NdJson,
Geoparquet(Option<Compression>),
}
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.
Geoparquet(Option<Compression>)
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::Format;
assert_eq!(Format::Json(false), Format::infer_from_href("item.json").unwrap());
sourcepub fn read<T: Href + FromJson + FromNdjson + FromGeoparquet>(
&self,
href: impl ToString,
) -> Result<T>
pub fn read<T: Href + FromJson + FromNdjson + FromGeoparquet>( &self, href: impl ToString, ) -> Result<T>
Reads a STAC object from an href in this format.
§Examples
use stac::{Format, Item};
let item: Item = Format::json().read("examples/simple-item.json").unwrap();
sourcepub fn from_path<T: FromJson + FromNdjson + FromGeoparquet + Href>(
&self,
path: impl AsRef<Path>,
) -> Result<T>
pub fn from_path<T: FromJson + FromNdjson + FromGeoparquet + Href>( &self, path: impl AsRef<Path>, ) -> Result<T>
Reads a local file in the given format.
§Examples
use stac::{Format, Item};
let item: Item = Format::json().from_path("examples/simple-item.json").unwrap();
sourcepub fn from_bytes<T: FromJson + FromNdjson + FromGeoparquet>(
&self,
bytes: impl Into<Bytes>,
) -> Result<T>
pub fn from_bytes<T: FromJson + FromNdjson + FromGeoparquet>( &self, bytes: impl Into<Bytes>, ) -> Result<T>
Reads a STAC object from some bytes.
§Examples
use stac::{Format, Item};
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 async fn get_opts<T, I, K, V>(
&self,
href: impl ToString,
options: I,
) -> Result<T>where
T: Href + FromJson + FromNdjson + FromGeoparquet,
I: IntoIterator<Item = (K, V)>,
K: AsRef<str>,
V: Into<String>,
Available on crate feature object-store
only.
pub async fn get_opts<T, I, K, V>(
&self,
href: impl ToString,
options: I,
) -> Result<T>where
T: Href + FromJson + FromNdjson + FromGeoparquet,
I: IntoIterator<Item = (K, V)>,
K: AsRef<str>,
V: Into<String>,
object-store
only.Gets a STAC value from an object store with the provided options.
§Examples
use stac::{Item, Format};
#[cfg(feature = "object-store-aws")]
{
let item: Item = stac::io::get_opts("s3://bucket/item.json", [("aws_access_key_id", "...")]).await.unwrap();
}
sourcepub fn write<T: ToJson + ToNdjson + IntoGeoparquet>(
&self,
path: impl AsRef<Path>,
value: T,
) -> Result<()>
pub fn write<T: ToJson + ToNdjson + IntoGeoparquet>( &self, path: impl AsRef<Path>, value: T, ) -> Result<()>
Writes a STAC value to the provided path.
§Examples
use stac::{Item, Format};
Format::json().write("an-id.json", Item::new("an-id")).unwrap();
sourcepub fn into_vec<T: ToJson + ToNdjson + IntoGeoparquet>(
&self,
value: T,
) -> Result<Vec<u8>>
pub fn into_vec<T: ToJson + ToNdjson + IntoGeoparquet>( &self, value: T, ) -> Result<Vec<u8>>
Converts a STAC object into some bytes.
§Examples
use stac::{Format, Item};
let item = Item::new("an-id");
let bytes = Format::json().into_vec(item).unwrap();
sourcepub async fn put_opts<T, I, K, V>(
&self,
href: impl ToString,
value: T,
options: I,
) -> Result<Option<PutResult>>where
T: ToJson + ToNdjson + IntoGeoparquet,
I: IntoIterator<Item = (K, V)>,
K: AsRef<str>,
V: Into<String>,
Available on crate feature object-store
only.
pub async fn put_opts<T, I, K, V>(
&self,
href: impl ToString,
value: T,
options: I,
) -> Result<Option<PutResult>>where
T: ToJson + ToNdjson + IntoGeoparquet,
I: IntoIterator<Item = (K, V)>,
K: AsRef<str>,
V: Into<String>,
object-store
only.Puts a STAC value to an object store with the provided options.
§Examples
use stac::{Item, Format};
let item = Item::new("an-id");
#[cfg(feature = "object-store-aws")]
{
Format::json().put_opts("s3://bucket/item.json", item, [("aws_access_key_id", "...")]).await.unwrap();
}
sourcepub fn geoparquet() -> Format
Available on crate feature geoparquet
only.
pub fn geoparquet() -> Format
geoparquet
only.Returns the default geoparquet format (no compression specified).
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more