Struct RecordData

Source
pub struct RecordData {
    pub location: usize,
    pub location_type: u8,
    pub hash_data: HashMap<usize, RecordCharacteristics>,
    pub record_counter: usize,
    pub data_base: String,
}

Fields§

§location: usize§location_type: u8§hash_data: HashMap<usize, RecordCharacteristics>§record_counter: usize§data_base: String

Implementations§

Source§

impl RecordData

Source

pub fn add_record_with_key<T>(&mut self, key_to_add: String, record: T)
where T: Base,

This method adds information to the database with a key as well.

§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record_with_key("mob".to_string(), "0404111222".to_string());
Source

pub fn add_record_with_key_exclusive<T>( &mut self, key_to_add: String, record: T, ) -> bool
where T: Base,

This method adds information to the database with a key as well. If the key already exists in the database, the information will not be added. The method returns true if successful, false, if they key exists already in the database.

§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record_with_key_exclusive("mob".to_string(), "0404111222".to_string());
Source

pub fn add_record<T>(&mut self, record: T)
where T: Base,

This method adds information to the database.

§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record("0404111222".to_string());
Source

pub fn delete_record(&mut self, record_number: usize)

This method deletes a record based on the supplied record number. If the record does not exist, it does nothing.

§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.delete_record(1);
database.delete_record(1000000); //This will do nothing since the 1000000 record does not exist.
Source

pub fn find(&self, what_to_find: &str) -> Vec<String>

Searches the database for a particular term and returns the matching record in a String vector consisting of two values for each match 1) The record id 2) The contents of the matching record.
 This method is available on read only databases (all methods work on writeable databases).
§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let found_records = loaded_database.find("great");
Source

pub fn find_key(&self, what_to_find: &str) -> Vec<String>

Searches the database key values (if a key value exists for a record- key values are optional) for a particular term and returns the matching record in a String vector consisting of two values for each match 1) The record id 2) The contents of the matching record. This method is available on read only databases (all methods work on writeable databases).

§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let found_records = loaded_database.find_key("great");
Source

pub fn get_record(&self, record_number: usize) -> Option<String>

This method returns a record. It returns None if the record does not exist. This is also available if a database is opened using the load_hash_database_read_only method.

§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let particular_record = loaded_database.get_record(1);
Source

pub fn length(&self) -> usize

This function returns the number of records stored in the database

§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.length();
Source

pub fn return_data_type(&self, record_number: usize) -> u8

This function returns the data type (e.g String, u64, f64 etc) of a stored value. This is based on the DataType enum.

§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.return_data_type(1);
Source

pub fn save_database(&self, filename: &str)

Saves a database hash table to a file. This will need to be run to save the database to a file. It is up to the user to impliment this action.

§Examples
use simplebase::engine::*;
let database = load_hash_database("test1base.txt");
database.save_database("test1base.txt");
Source

pub fn save_database_every(&self, filename: &str, save_cycle: usize) -> bool

Saves a database hash table to a file every ## cycles. This is useful in high intensity/write scenarios where you could have 1000s of saves a second. To increase performance you could use this function. The only drawback is that if the server goes down, you could potentially lose a small amount of data since the last save. Keep in mind that some form of save function will need to be run to save the database to a file. It is up to the user to impliment this action. This function returns false if the database is not saved, true if it is.

§Examples
use simplebase::engine::*;
let database = load_hash_database("test1base.txt");
database.save_database_every("test1base.txt", 10);
Source

pub fn verify_record(&self, record_number: usize) -> bool

Calculates a simple chksum on the contents of a record and compares it to the stored chksum. This will return false if there is a mismatch. If the record does not exist, it will still return true.

§Examples
use simplebase::engine::*;
let mut database = new_empty_database();
database.add_record_with_key_exclusive("mob".to_string(), "0404111222".to_string());
let result = database.verify_record(1);
assert_eq!(true,result);
Source

pub fn verify_database(&self) -> usize

Checks the checksum in the database for each record. If it does not match, a message is printed stated which record has potentially being corrupted. It also returns the amount of corrupted records if there are any. If zero is returned this means that there are no corrupted records.

§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
loaded_database.verify_database();

Trait Implementations§

Source§

impl Debug for RecordData

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RecordData

Source§

fn default() -> RecordData

Returns the “default value” for a type. 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, 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.