opus-db 0.1.0

test database implementation
Documentation
use bitflags::bitflags;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::result;

// TODO: Implement PermissionSet
bitflags!{
    struct PermissionSet: u8 {
        const READ = 0x01;
        const WRITE = 0x02;
        const LOG = 0x04;
    }
}
pub type Id = String;

pub struct Attribute {
    current_state: String, // XXX: what should this type be?
    parent: Option<Id>,
    base_dir: PathBuf,
    participants: HashMap<Id, PermissionSet>,
    children: HashSet<Id>,
    log_buffer: io::BufWriter<fs::File>,
}

impl Attribute {
    // new returns a new Attribute struct.
    // For now, we assume that some other struct will be responsible for generating its id.
    fn new<P: AsRef<Path>>(id: Id, parent_path: P, parent: Option<Id>) -> Self {
        // Make base_dir_dir.
        let base_dir = parent_path.as_ref().join(id);
        fs::create_dir(&base_dir).unwrap_or(());

        // Make log buffer
        let file_log =
            fs::File::create(&base_dir.join("log")).unwrap_or(panic!("Could not open file"));
        let log_buffer = io::BufWriter::new(file_log);

        Attribute {
            current_state: String::new(),
            base_dir,
            log_buffer,
            parent,
            participants: HashMap::new(),
            children: HashSet::new(),
        }
    }

    // TODO: implement method
    fn add_participant(&self, id: Id, permissions: PermissionSet) -> AttributeResult {
        unimplemented!();
    }

    fn remove_participant(&mut self, participant_id: Id) -> Option<Id> {
        match self.participants.remove(&participant_id) {
            Some(_) => Some(participant_id),
            None => None,
        }
    }
}

type AttributeResult = result::Result<Attribute, io::Error>;