Enum Format

Source
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

Source

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

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");
Source

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

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

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

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

pub fn into_vec<T: Writeable>(&self, value: T) -> Result<Vec<u8>>

Converts a STAC object into some bytes.

§Examples
use stac::Item;
use stac_io::Format;

let item = Item::new("an-id");
let bytes = Format::json().into_vec(item).unwrap();
Source

pub fn json() -> Format

Returns the default JSON format (compact).

Source

pub fn ndjson() -> Format

Returns the newline-delimited JSON format.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

Returns a duplicate 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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§

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<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<T> ErasedDestructor for T
where T: 'static,