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]

Create a new TrailDB constructor.

Add an event to the constructor.

Close a constructor without writing it to disk.

Write the TrailDB to disk and close it.

Combine an already finalized TrailDB with a constructor.

Trait Implementations

impl Drop for Constructor
[src]

A method called when the value goes out of scope. Read more