cmte 5 years ago
parent
commit
c564b27c82
3 changed files with 79 additions and 0 deletions
  1. 5 0
      Cargo.lock
  2. 9 0
      Cargo.toml
  3. 65 0
      src/main.rs

+ 5 - 0
Cargo.lock

@@ -0,0 +1,5 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "rusted-mem"
+version = "0.1.0"

+ 9 - 0
Cargo.toml

@@ -0,0 +1,9 @@
+[package]
+name = "rusted-mem"
+version = "0.1.0"
+authors = ["Douglas Andreani <cmtedouglas@hotmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]

+ 65 - 0
src/main.rs

@@ -0,0 +1,65 @@
+
+struct Nodes<T> {
+     data: Vec<DataNode<T>>
+}
+
+impl<T> Nodes<T> {
+    fn new() -> Nodes<T> {
+        Nodes {
+            data: Vec::new()
+        }
+    }
+
+    fn add_node(&mut self, member: DataNode<T>) {
+        self.data.push(member)
+    }
+
+    fn is_empty(&mut self) -> bool {
+        self.data.len() == 0
+    }
+
+    fn pop_node(&mut self) -> Option<DataNode<T>>{
+        self.data.pop()
+    }
+}
+
+struct DataNode<T> {
+    key: String,
+    value: Option<T>
+}
+
+impl<T> DataNode<T> {
+    fn new(t_key: &str, t_value: Option<T>) -> DataNode<T>{
+        DataNode {
+            key: String::from(t_key),
+            value: Option::from(t_value)
+        }
+    }
+}
+
+
+fn main() {
+    let mut n = Nodes::new();
+
+    let d = DataNode::new("Key1", Option::from("Hello"));
+    let c = DataNode::new("Key2", Option::from("World"));
+
+    n.add_node(d);
+    n.add_node(c);
+
+
+    while !n.is_empty() {
+        let dd = n.pop_node();
+        match dd {
+            None => println!("Nodes not initialized",),
+            Some(node) => {
+                match node.value {
+                    None =>println!("Key {} Value: NULL", node.key),
+                    Some(value) => println!("Key {} Value: {:?}", node.key, value),
+                }
+            }
+        }
+    }
+}
+
+