Skip to main content

DocDefinition

Struct DocDefinition 

Source
pub struct DocDefinition {
    pub kind: String,
    pub version: u64,
    pub semantics: DocSemantics,
    pub initial: Box<dyn Fn(&Value) -> Value + Send + Sync>,
    pub migrate: Option<Box<dyn Fn(&JsonObject, u64) -> Result<Value, String> + Send + Sync>>,
    pub checkpoint_when: Option<Box<dyn Fn(&DocDefinition, &Value, &[Op], CheckpointInfo) -> Result<bool, String> + Send + Sync>>,
}
Expand description

A document definition. initial receives null (upstream’s family seed) and runs only when the document is absent; migrate converts a stored value of an older version; checkpoint_when returning true stores an ordinary change as a complete base instead of a delta.

Fields§

§kind: String

Stable persisted kind; part of the public protocol.

§version: u64

Positive integer version of the stored value shape.

§semantics: DocSemantics§initial: Box<dyn Fn(&Value) -> Value + Send + Sync>§migrate: Option<Box<dyn Fn(&JsonObject, u64) -> Result<Value, String> + Send + Sync>>§checkpoint_when: Option<Box<dyn Fn(&DocDefinition, &Value, &[Op], CheckpointInfo) -> Result<bool, String> + Send + Sync>>

Implementations§

Source§

impl DocDefinition

Source

pub fn new( kind: &str, version: u64, semantics: DocSemantics, initial: impl Fn(&Value) -> Value + Send + Sync + 'static, ) -> DocDefinition

Source

pub fn migrate( self, migrate: impl Fn(&JsonObject, u64) -> Result<Value, String> + Send + Sync + 'static, ) -> Self

Source

pub fn checkpoint_when( self, predicate: impl Fn(&DocDefinition, &Value, &[Op], CheckpointInfo) -> Result<bool, String> + Send + Sync + 'static, ) -> Self

Source

pub fn define(self) -> Result<Doc, SessionError>

Validate and share the definition (upstream defineDoc).

Trait Implementations§

Source§

impl Debug for DocDefinition

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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.