Struct traildb::Constructor
[−]
[src]
pub struct Constructor { /* fields omitted */ }
A structure that represents a TrailDB
constructor.
A constructor lives in RAM. All events are added to the constructor.
After being written to disk, the TrailDB
is immutable.
Examples
use traildb::{Constructor, Uuid}; use std::path::Path; // Names relevent to our event type let db_fields = ["user", "action"]; // Where to write our dabase to disk when we're done adding events to it let db_path = Path::new("my_traildb"); // Create a constructor let mut cons = Constructor::new(db_path, &db_fields).unwrap(); // Let's gather necessary data to create and event // Time is stored as a `u64`. What that represents (e.g. UNIX time) is up to you let timestamp: u64 = 0; // Every trail need a UUID let uuid: Uuid = [0u8;16]; // The values for for fields `"user"` and `"action"` let event_vals = ["Alice", "login"]; // Now lets add our event data to the constructor assert!(cons.add(&uuid, timestamp, &event_vals).is_ok()); // Finally, let's write our database to disk by calling `finalize` assert!(cons.finalize().is_ok());
Methods
impl Constructor
[src]
fn new(path: &Path, fields: &[&str]) -> Result<Self, Error>
Create a new TrailDB constructor.
fn add(
&mut self,
uuid: &Uuid,
timestamp: Timestamp,
values: &[&str]
) -> Result<(), Error>
&mut self,
uuid: &Uuid,
timestamp: Timestamp,
values: &[&str]
) -> Result<(), Error>
Add an event to the constructor.
fn close(&mut self)
Close a constructor without writing it to disk.
fn finalize(&mut self) -> Result<(), Error>
Write the TrailDB to disk and close it.
fn append(&mut self, db: &Db) -> Result<(), Error>
Combine an already finalized TrailDB with a constructor.