Struct airone::database::AironeDb

source ·
pub struct AironeDb<T, SaveMode = AutoSave>
where T: InnerStruct, SaveMode: SaveModeExt,
{ /* private fields */ }

Implementations§

source§

impl<T: InnerStruct, SaveMode: SaveModeExt> AironeDb<T, SaveMode>

source

pub fn new() -> Result<Self, Error>

source

pub fn new_with_custom_name(custom_name: &str) -> Result<Self, Error>

source

pub fn get_all(&self) -> &[T]

source

pub fn get(&self, index: usize) -> Option<&T>

source

pub fn get_mut(&mut self, index: usize) -> Option<WriteProxy<'_, T, SaveMode>>

Mutably access the element at the specified index

source

pub fn len(&self) -> usize

Returns the number of elements in the list

source

pub fn is_empty(&self) -> bool

Checks if the inner array is empty

source

pub fn set_buffer_mode(&mut self, mode: BufferMode) -> Result<(), Error>

source

pub fn iter(&self) -> impl Iterator<Item = &T>

source

pub fn set_save_mode<NewSaveMode: SaveModeExt>( self ) -> Result<AironeDb<T, NewSaveMode>, Error>

Change the SaveMode to the provided value

For example, you can convert a db to ManualSave or AutoSave mode. While changing mode, any pending change is written to disk and you won’t be able to rollback.

source§

impl<T: InnerStruct> AironeDb<T, AutoSave>

source

pub fn insert(&mut self, index: usize, element: T) -> Result<(), Error>

Inserts an element at position index within the vector, shifting all elements after it to the right.

§Panics

Panics if index > len.

source

pub fn push(&mut self, element: T) -> Result<(), Error>

Adds a new element to the end of the list

source

pub fn pop(&mut self) -> Result<Option<T>, Error>

Removes the last element of the list and returns it if existing

source

pub fn extend(&mut self, iter: impl Iterator<Item = T>) -> Result<(), Error>

Adds the elements of an iterator to the end of the list.

source

pub fn append(&mut self, other: &mut Vec<T>) -> Result<(), Error>

Adds multiple elements to the end of the list, automatically reducing the number of syscalls to write them to disk

Works similar to https://doc.rust-lang.org/std/vec/struct.Vec.html#method.append

source

pub fn dedup(&mut self) -> Result<(), Error>
where T: PartialEq,

Removes consecutive duplicates

source

pub fn remove(&mut self, index: usize) -> Result<T, Error>

Removes and returns the element at index. Panics if out of bounds.

source

pub fn drain( &mut self, range: impl RangeBounds<usize> ) -> Result<impl Iterator<Item = T>, Error>

Removes the specified range in bulk and returns an iterator over the removed elements

source

pub fn retain<F: Fn(&T) -> bool>(&mut self, f: F) -> Result<(), Error>

Keeps only the elements that match the predicate

Removes all the elements that do not satisfy the condition

source

pub fn clear(&mut self) -> Result<(), Error>

Deletes all elements from the list

source

pub fn set<V: SerializableField>( &mut self, index: usize, fieldname: &'static str, value: V ) -> Result<(), Error>

source§

impl<T: InnerStruct> AironeDb<T, ManualSave>

source

pub fn insert(&mut self, index: usize, element: T)

Inserts an element at position index within the vector, shifting all elements after it to the right.

§Panics

Panics if index > len.

source

pub fn push(&mut self, element: T)

Adds a new element to the end of the list

source

pub fn pop(&mut self) -> Option<T>

Removes the last element of the list and returns it if existing

source

pub fn extend(&mut self, iter: impl Iterator<Item = T>)

Adds the elements of an iterator to the end of the list.

source

pub fn append(&mut self, other: &mut Vec<T>)

Adds multiple elements to the end of the list, automatically reducing the number of syscalls to write them to disk

Works similar to https://doc.rust-lang.org/std/vec/struct.Vec.html#method.append

source

pub fn dedup(&mut self)
where T: PartialEq,

Removes consecutive duplicates

source

pub fn remove(&mut self, index: usize) -> T

Removes and returns the element at index. Panics if out of bounds.

source

pub fn drain( &mut self, range: impl RangeBounds<usize> ) -> impl Iterator<Item = T>

Removes the specified range in bulk and returns an iterator over the removed elements

source

pub fn retain<F: Fn(&T) -> bool>(&mut self, f: F)

Keeps only the elements that match the predicate

Removes all the elements that do not satisfy the condition

source

pub fn clear(&mut self)

Deletes all elements from the list

source

pub fn set<V: SerializableField>( &mut self, index: usize, fieldname: &'static str, value: V )

source

pub fn save(&mut self) -> Result<(), Error>

Saves to file all in-memory transactions, to persist the current db state.

source

pub fn rollback(&mut self)

Rollbacks the data in memory to the last known state which was persisted to disk

Trait Implementations§

source§

impl<T, SaveMode> Index<usize> for AironeDb<T, SaveMode>
where T: InnerStruct, SaveMode: SaveModeExt,

External traits

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T, SaveMode> Freeze for AironeDb<T, SaveMode>

§

impl<T, SaveMode> RefUnwindSafe for AironeDb<T, SaveMode>
where SaveMode: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, SaveMode> Send for AironeDb<T, SaveMode>
where SaveMode: Send, T: Send,

§

impl<T, SaveMode> Sync for AironeDb<T, SaveMode>
where SaveMode: Sync, T: Sync,

§

impl<T, SaveMode> Unpin for AironeDb<T, SaveMode>
where SaveMode: Unpin, T: Unpin,

§

impl<T, SaveMode> UnwindSafe for AironeDb<T, SaveMode>
where SaveMode: UnwindSafe, T: 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>,

§

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

§

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.