Enum stac::Format

source ·
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

source

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());
source

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();
source

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();
source

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();
source

pub async fn get_opts<T, I, K, V>( &self, href: impl ToString, options: I, ) -> Result<T>

Available on crate feature 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();
}
source

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();
source

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();
source

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>,

Available on crate feature 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();
}
source

pub fn json() -> Format

Returns the default JSON format (compact).

source

pub fn ndjson() -> Format

Returns the newline-delimited JSON format.

source

pub fn geoparquet() -> Format

Available on crate feature geoparquet only.

Returns the default geoparquet format (no compression specified).

Trait Implementations§

source§

impl Clone for Format

source§

fn clone(&self) -> Format

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Format

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Format

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Format

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Format

source§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Format>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Format

source§

fn eq(&self, other: &Format) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Format

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

source§

fn is_within(&self, b: &G2) -> bool

source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,