mp 0.1.0

Universal programming utility for GUI.
/* ------------------------------------------------------------
    Machine Pseudo-Code
    Project.Github: "https://github.com/kerryeon/mp"
---------------------------------------------------------------
    Author:
        Name: "kerryeon"
        Email: "besqer996@gnu.ac.kr"
        Github: "https://github.com/kerryeon"
    Generated:
        Date: "2/22/2019"
------------------------------------------------------------ */

use std::collections::btree_map::BTreeMap;

type ID = usize;
type Binary = Vec<u8>;

const NIL: ID = 0;

pub trait Builder {
    fn new() -> Self;
    fn from_raw(raw: Binary) -> Self;
    fn to_raw(&self) -> Binary;
}

pub struct Node<T> where T: Builder + Clone {
    key: T,
    now: ID,
    parent: ID,
    next: ID,
}

impl<T> Builder for Node<T> where T: Builder + Clone {
    // Builder
    fn new() -> Self {
        Self {
            key: T::new(),
            now: NIL,
            parent: NIL,
            next: NIL,
        }
    }
    fn from_raw(raw: Binary) -> Self {unimplemented!()}
    fn to_raw(&self) -> Binary {unimplemented!()}
}

pub type Tree<T> = Vec<Node<T>>;

trait DynamicTree<T> where T: Builder + Clone {
    // Builder
    fn new() -> Self;
    fn from_raw(raw: Binary) -> Self;
    fn to_raw(&self) -> Binary;
    // Insert
    fn add(&mut self) -> &mut Node<T>;
    // Find / Search
    /*fn get(&mut self, id: ID) -> &Node;
    fn get_mut(&mut self, id: ID) -> &mut Node;
    // Change
    fn change_parent(&mut self, id: ID, parent: ID);
    // Remove
    fn remove_recursive(&mut self, id: ID) -> Option<()>;
    fn remove_safe(&mut self, id: ID) -> Option<()>;*/
}

impl<T> DynamicTree<T> for Tree<T> where T: Builder + Clone {
    // Builder
    fn new() -> Self {
        Self::new()
    }
    fn from_raw(raw: Binary) -> Self {
        unimplemented!()
    }
    fn to_raw(&self) -> Binary {
        unimplemented!()
    }
    // Insert
    fn add(&mut self) -> &mut Node<T> {
        let node: Node<T> = Node::new();
        self.push(node);
        unimplemented!()
    }
}