pub struct Table {
pub name: String,
pub primary_field: FieldType,
pub fields: HashMap<String, FieldRequirement>,
pub expire_after: Option<Duration>,
/* private fields */
}
Expand description
Table is a collection of Entry objects that meet a specified format criteria
Fields§
§name: String
§primary_field: FieldType
§fields: HashMap<String, FieldRequirement>
§expire_after: Option<Duration>
Implementations§
Source§impl Table
impl Table
Sourcepub fn new() -> TableBuilder
pub fn new() -> TableBuilder
Returns a TableBuilder Instance that will be used to create a new table
use persistent_keystore_rs::Table;
let table = Table::new();
Sourcepub fn get(&self, key: &Field) -> Result<&Entry, DatabaseError>
pub fn get(&self, key: &Field) -> Result<&Entry, DatabaseError>
Returns a reference to an Entry within the Table matching the primary Field If the primary Field does not exist, DatabaseError::EntryDoesNotExists is returned.
use persistent_keystore_rs::Field;
let result = table.get(&Field::String("MyFirstEntry".to_string())).unwrap();
Sourcepub fn insert(&mut self, entry: Entry) -> Result<(), DatabaseError>
pub fn insert(&mut self, entry: Entry) -> Result<(), DatabaseError>
Inserts the provided entry into the Table If the primary Field exists, DatabaseError::EntryExists is returned.
use persistent_keystore_rs::{Entry, Field};
let entry = Entry::new()
.set_primary_field(Field::String("MyFirstEntry".to_string())).unwrap()
.add_field("TimeStamp".to_string(), Field::Date(SystemTime::now())).unwrap()
.build().unwrap();
table.insert(entry).unwrap();
Sourcepub fn insert_or_update(&mut self, entry: Entry) -> Result<(), DatabaseError>
pub fn insert_or_update(&mut self, entry: Entry) -> Result<(), DatabaseError>
Inserts the provided entry if it doesn’t exist, or updates if it does
use persistent_keystore_rs::{Entry, Field};
let entry = Entry::new()
.set_primary_field(Field::String("MyFirstEntry".to_string())).unwrap()
.add_field("TimeStamp".to_string(), Field::Date(SystemTime::now())).unwrap()
.build().unwrap();
table.insert_or_update(entry).unwrap();
let entry2 = Entry::new()
.set_primary_field(Field::String("MyFirstEntry".to_string())).unwrap()
.add_field("TimeStamp".to_string(), Field::Date(SystemTime::now())).unwrap()
.build().unwrap();
table.insert_or_update(entry2).unwrap();
Sourcepub fn update(&mut self, entry: Entry) -> Result<(), DatabaseError>
pub fn update(&mut self, entry: Entry) -> Result<(), DatabaseError>
Updates the provided entry within the Table. If the Entry does not exist, DatabaseError:EntryDoesNotExists is returned
use persistent_keystore_rs::{Entry, Field};
let entry = Entry::new()
.set_primary_field(Field::String("MyFirstEntry".to_string())).unwrap()
.add_field("TimeStamp".to_string(), Field::Date(SystemTime::now())).unwrap()
.build().unwrap();
table.update(entry).unwrap();
Sourcepub fn delete(&mut self, primary_field: Field) -> Result<(), DatabaseError>
pub fn delete(&mut self, primary_field: Field) -> Result<(), DatabaseError>
Deletes the entry with the associated primary_field from the Table. If the Entry does not exist, DatabaseError:EntryDoesNotExists is returned
use persistent_keystore_rs::Field;
table.delete(Field::String("MyFirstEntry".to_string())).unwrap();
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Table
impl<'de> Deserialize<'de> for Table
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Table
impl RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnwindSafe for Table
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more