From 02481656966b0a8dfc95cf3c22bcc049660ff7d4 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sat, 26 Dec 2020 17:48:38 +0000 Subject: Move Rust exercises in a subdirectory --- dot-dsl/src/lib.rs | 119 ----------------------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 dot-dsl/src/lib.rs (limited to 'dot-dsl/src/lib.rs') diff --git a/dot-dsl/src/lib.rs b/dot-dsl/src/lib.rs deleted file mode 100644 index 654ee09..0000000 --- a/dot-dsl/src/lib.rs +++ /dev/null @@ -1,119 +0,0 @@ -pub mod graph { - - use graph_items::edge::Edge; - use graph_items::node::Node; - use std::collections::HashMap; - - pub mod graph_items { - - pub mod node { - - use std::collections::HashMap; - - #[derive(Default, Debug, PartialEq, Eq, Clone)] - pub struct Node<'a> { - pub name: &'a str, - attrs: HashMap, - } - - impl<'a> Node<'a> { - pub fn new(name: &'a str) -> Node<'a> { - Node { - name, - ..Default::default() - } - } - - pub fn with_attrs(mut self, attrs: &[(&'a str, &'a str)]) -> Node<'a> { - for (key, value) in attrs { - self.attrs.insert(key.to_string(), value.to_string()); - } - self - } - - pub fn get_attr(&self, key: &str) -> Option<&str> { - self.attrs.get(key).map(|s| &s[..]) - } - } - } - - pub mod edge { - - use std::collections::HashMap; - - #[derive(Default, Debug, PartialEq, Eq, Clone)] - pub struct Edge<'a> { - pub x: &'a str, - pub y: &'a str, - attrs: HashMap, - } - - impl<'a> Edge<'a> { - pub fn new(x: &'a str, y: &'a str) -> Edge<'a> { - Edge { - x, - y, - ..Default::default() - } - } - - pub fn with_attrs(mut self, attrs: &[(&'a str, &'a str)]) -> Edge<'a> { - for (key, value) in attrs { - self.attrs.insert(key.to_string(), value.to_string()); - } - self - } - - pub fn get_attr(&self, key: &str) -> Option<&str> { - self.attrs.get(key).map(|s| &s[..]) - } - } - } - } - - #[derive(Default, Debug)] - pub struct Graph<'a> { - pub nodes: Vec>, - pub edges: Vec>, - pub attrs: HashMap, - } - - impl<'a> Graph<'a> { - pub fn new() -> Self { - Default::default() - } - - pub fn with_attrs(mut self, attrs: &[(&'a str, &'a str)]) -> Graph<'a> { - for (key, value) in attrs { - self.attrs.insert(key.to_string(), value.to_string()); - } - self - } - - pub fn with_nodes(mut self, nodes: &[Node<'a>]) -> Graph<'a> { - for node in nodes { - self.nodes.push(node.clone()); - } - self - } - - pub fn with_edges(mut self, edges: &[Edge<'a>]) -> Graph<'a> { - for edge in edges { - self.edges.push(edge.clone()) - } - self - } - - pub fn get_node(&self, name: &str) -> Option<&Node<'a>> { - self.nodes.iter().find(|&node| node.name == name) - } - - pub fn get_edge(&self, x: &str, y: &str) -> Option<&Edge<'a>> { - self.edges.iter().find(|&edge| edge.x == x && edge.y == y) - } - - pub fn get_attr(&self, key: &str) -> Option<&str> { - self.attrs.get(key).map(|s| &s[..]) - } - } -} -- cgit v1.2.3