pub struct Format<D> { /* private fields */ }Expand description
How documents of type D are stored.
Implementations§
Source§impl<D: Serialize + DeserializeOwned> Format<D>
impl<D: Serialize + DeserializeOwned> Format<D>
Sourcepub fn new(id: impl Into<String>, generator: impl Into<String>) -> Format<D>
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").
Sourcepub fn migrations(self, m: Vec<Migration>) -> Self
pub fn migrations(self, m: Vec<Migration>) -> Self
The migration chain ([v1→v2, v2→v3, …]).
Sourcepub fn payload_key(self, key: impl Into<String>) -> Self
pub fn payload_key(self, key: impl Into<String>) -> Self
The envelope key holding the document (default "document").
Sourcepub fn legacy(self, probe: LegacyProbe) -> Self
pub fn legacy(self, probe: LegacyProbe) -> Self
Recognise bare pre-envelope documents.
Sourcepub fn oldest(self, v: u64) -> Self
pub fn oldest(self, v: u64) -> Self
Refuse files older than v (FormatError::TooOld).
Sourcepub fn pretty(self, on: bool) -> Self
pub fn pretty(self, on: bool) -> Self
Indented (diffable, the default) or compact (autosaves) output.
Sourcepub fn extras_after_payload(self, on: bool) -> Self
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.
Sourcepub fn accept_untagged(self, on: bool) -> Self
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.
pub fn id(&self) -> &str
Sourcepub fn schema_version(&self) -> u64
pub fn schema_version(&self) -> u64
The schema this build writes and the newest it reads.
Sourcepub fn encode(&self, doc: &D) -> Result<Vec<u8>, FormatError>
pub fn encode(&self, doc: &D) -> Result<Vec<u8>, FormatError>
The file bytes for doc in the current schema.
Sourcepub fn encode_with(
&self,
doc: &D,
extras: &Map<String, Value>,
) -> Result<Vec<u8>, FormatError>
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).