Skip to main content

Format

Struct Format 

Source
pub struct Format<D> { /* private fields */ }
Expand description

How documents of type D are stored.

Implementations§

Source§

impl<D: Serialize + DeserializeOwned> Format<D>

Source

pub fn new(id: impl Into<String>, generator: impl Into<String>) -> Format<D>

Files tagged id (e.g. "acme.drawing"), written by generator (e.g. "Acme Draw 1.2.0").

Source

pub fn migrations(self, m: Vec<Migration>) -> Self

The migration chain ([v1→v2, v2→v3, …]).

Source

pub fn payload_key(self, key: impl Into<String>) -> Self

The envelope key holding the document (default "document").

Source

pub fn legacy(self, probe: LegacyProbe) -> Self

Recognise bare pre-envelope documents.

Source

pub fn oldest(self, v: u64) -> Self

Refuse files older than v (FormatError::TooOld).

Source

pub fn pretty(self, on: bool) -> Self

Indented (diffable, the default) or compact (autosaves) output.

Source

pub fn max_bytes(self, n: u64) -> Self

Refuse files larger than this.

Source

pub fn extras_after_payload(self, on: bool) -> Self

Write extra envelope keys after the payload key instead of before it (default false). Reading accepts either order.

Source

pub fn accept_untagged(self, on: bool) -> Self

Read envelopes that have no format tag (early files) when they have a schema_version and the payload key; such files are reported with this format’s id. Off by default: they are refused as FormatError::NotThisFormat. A format tag naming another format is always refused.

Source

pub fn id(&self) -> &str

Source

pub fn schema_version(&self) -> u64

The schema this build writes and the newest it reads.

Source

pub fn encode(&self, doc: &D) -> Result<Vec<u8>, FormatError>

The file bytes for doc in the current schema.

Source

pub fn encode_with( &self, doc: &D, extras: &Map<String, Value>, ) -> Result<Vec<u8>, FormatError>

Format::encode with extra envelope keys (envelope fields and the payload key win).

Source

pub fn save(&self, path: &Path, doc: &D) -> Result<(), FormatError>

Encode and write doc to path durably.

Source

pub fn load(&self, path: &Path) -> Result<Loaded<D>, FormatError>

Read a file from disk.

Source

pub fn decode(&self, bytes: &[u8]) -> Result<Loaded<D>, FormatError>

Read file bytes (any supported schema).

Trait Implementations§

Source§

impl<D> Debug for Format<D>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D> Freeze for Format<D>
where PhantomData<fn() -> D>: Freeze,

§

impl<D> RefUnwindSafe for Format<D>
where PhantomData<fn() -> D>: RefUnwindSafe,

§

impl<D> Send for Format<D>
where PhantomData<fn() -> D>: Send,

§

impl<D> Sync for Format<D>
where PhantomData<fn() -> D>: Sync,

§

impl<D> Unpin for Format<D>
where PhantomData<fn() -> D>: Unpin,

§

impl<D> UnsafeUnpin for Format<D>
where PhantomData<fn() -> D>: UnsafeUnpin,

§

impl<D> UnwindSafe for Format<D>
where PhantomData<fn() -> D>: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.