Skip to main content

MemoryDatabase

Struct MemoryDatabase 

Source
pub struct MemoryDatabase { /* private fields */ }
Expand description

Records kept in memory, on desktop and in the browser. Any number of spaces share them, and each sees what the others committed.

With Self::stored_in they are also kept in a Storage between runs: read when it opens, written after every commit. Self::export_json and Self::import_json move all of them in and out at once.

Implementations§

Source§

impl MemoryDatabase

Source

pub fn new(entities: Vec<EntityInfo>) -> Result<Self, ModelError>

A database with these entities and no records.

Source

pub fn stored_in( self, storage: impl Storage + 'static, name: impl Into<String>, ) -> Result<Self, SpaceError>

Keeps the records in storage under name: what is there is read now, and every commit writes them all back. Records of entities the database no longer has are left out.

Source

pub fn was_restored(&self) -> bool

Whether Self::stored_in found records kept from before, so an app can put its first records in only once.

Source

pub fn storage_problem(&self) -> Option<String>

What went wrong the last time the records were written to their storage, if it did.

Source

pub fn export_json(&self) -> String

Every record, as JSON: {"format": 1, "next_key": 7, "records": {"Account": [{...}]}}. Dates are {"days": .., "seconds": ..}; the rest are plain JSON values.

Source

pub fn import_json(&self, text: &str) -> Result<usize, SpaceError>

Puts these records, as Self::export_json writes them, in place of all there are, and keeps them if the database is stored. Returns how many there are. Nothing changes if anything is wrong: an entity it does not have, a record without its key, a value that cannot be read.

Source

pub fn space(&self) -> MemoryObjectSpace

A new unit of work over these records.

Trait Implementations§

Source§

impl Clone for MemoryDatabase

Source§

fn clone(&self) -> MemoryDatabase

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryDatabase

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