Skip to content

Commit

Permalink
define the dom
Browse files Browse the repository at this point in the history
  • Loading branch information
muathendirangu committed Oct 12, 2023
1 parent d6cc15c commit e23e7f9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb


# Added by cargo

/target
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "render"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
32 changes: 32 additions & 0 deletions src/dom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::collections::HashMap;


type AttributeMap = HashMap<String,String>;

struct ElementData{
tag_name: String,
attributes: AttributeMap,
}
enum NodeType {
Text(String),
Element(ElementData),
}
struct Node {
children: Vec<Node>,
node_type: NodeType,
}

fn text(text: String) -> Node {
Node{
children: Vec::new(),node_type: NodeType::Text(text),
}
}

fn element(name: String, attrs: AttributeMap, children: Vec<Node>) -> Node {
Node { children: children, node_type: NodeType::Element(
ElementData{
tag_name: name,
attributes: attrs,
}
) }
}
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod dom;

fn main() {
println!("Hello, world!");
}

0 comments on commit e23e7f9

Please sign in to comment.