[−][src]Trait spartan_lib::core::db::Database
Interface for working with databases
Associated Types
type PositionKey: Copy
[src]
Required methods
pub fn push_raw(&mut self, message: M)
[src]
Push raw message to database
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; use spartan_lib::core::message::builder::MessageBuilder; let mut db = VecDatabase::default(); let message = MessageBuilder::default().body("Hello, world").compose().unwrap(); db.push_raw(message);
pub fn position<F>(&self, predicate: F) -> Option<Self::PositionKey> where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,
Get database position key of the first message, that matches predicate
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; use spartan_lib::core::message::builder::MessageBuilder; use spartan_lib::core::payload::Dispatchable; let mut db = VecDatabase::default(); let message = MessageBuilder::default().body("Hello, world").compose().unwrap(); db.push_raw(message); assert_eq!(db.position(|msg| msg.obtainable()).unwrap(), 0);
pub fn get(&self, position: Self::PositionKey) -> Option<&M>
[src]
Get shared message reference by database position key
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; use spartan_lib::core::message::builder::MessageBuilder; use spartan_lib::core::payload::Dispatchable; let mut db = VecDatabase::default(); let message = MessageBuilder::default().body("Hello, world").compose().unwrap(); db.push_raw(message); let position = db.position(|msg| msg.obtainable()).unwrap(); assert!(db.get(position).unwrap().obtainable());
pub fn get_mut(&mut self, position: Self::PositionKey) -> Option<&mut M>
[src]
Get mutable message reference by database position key
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; use spartan_lib::core::message::builder::MessageBuilder; use spartan_lib::core::payload::{Dispatchable, Status}; let mut db = VecDatabase::default(); let message = MessageBuilder::default().body("Hello, world").compose().unwrap(); db.push_raw(message); let position = db.position(|msg| msg.obtainable()).unwrap(); db.get_mut(position).unwrap().reserve();
pub fn delete_pos(&mut self, position: Self::PositionKey) -> Option<M>
[src]
Delete message by database position key
Returns owned message if position key is present in database
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; use spartan_lib::core::message::builder::MessageBuilder; use spartan_lib::core::payload::Dispatchable; let mut db = VecDatabase::default(); let message = MessageBuilder::default().body("Hello, world").compose().unwrap(); db.push_raw(message); let position = db.position(|msg| msg.obtainable()).unwrap(); db.delete_pos(position).unwrap();
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,
Retain only messages, that match predicate
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; let mut db = VecDatabase::default(); db.push_raw(1); db.push_raw(2); db.push_raw(3); db.retain(|msg| *msg == 1 || *msg == 2); assert_eq!(db.position(|msg| *msg == 2).unwrap(), 1);
pub fn len(&self) -> usize
[src]
Get database size
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; let mut db = VecDatabase::default(); db.push_raw(1); db.push_raw(2); db.push_raw(3); assert_eq!(db.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Check if database is empty
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; let mut db = VecDatabase::default(); db.push_raw(1); assert!(!db.is_empty());
pub fn clear(&mut self)
[src]
Remove all database messages
use spartan_lib::core::db::Database; use spartan_lib::core::db::VecDatabase; let mut db = VecDatabase::default(); db.push_raw(1); db.clear(); assert!(db.is_empty());
Implementors
impl<M> Database<M> for TreeDatabase<M> where
M: Identifiable + Sortable,
<M as Identifiable>::Id: Hash,
[src]
M: Identifiable + Sortable,
<M as Identifiable>::Id: Hash,
type PositionKey = <M as Identifiable>::Id
pub fn push_raw(&mut self, message: M)
[src]
pub fn position<F>(&self, predicate: F) -> Option<Self::PositionKey> where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,
pub fn get(&self, position: Self::PositionKey) -> Option<&M>
[src]
pub fn get_mut(&mut self, position: Self::PositionKey) -> Option<&mut M>
[src]
pub fn delete_pos(&mut self, position: Self::PositionKey) -> Option<M>
[src]
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,
pub fn len(&self) -> usize
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn clear(&mut self)
[src]
impl<M> Database<M> for VecDatabase<M>
[src]
type PositionKey = usize
pub fn push_raw(&mut self, message: M)
[src]
pub fn position<F>(&self, predicate: F) -> Option<Self::PositionKey> where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,
pub fn get(&self, position: Self::PositionKey) -> Option<&M>
[src]
pub fn get_mut(&mut self, position: Self::PositionKey) -> Option<&mut M>
[src]
pub fn delete_pos(&mut self, position: Self::PositionKey) -> Option<M>
[src]
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(&M) -> bool,
[src]
F: Fn(&M) -> bool,