Skip to content

Commit

Permalink
Create rust project and implement the DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
vallezw committed Jun 24, 2022
0 parents commit 5568f63
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

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

[dependencies]
34 changes: 34 additions & 0 deletions src/dom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
struct Node {
// data common to all nodes:
children: Vec<Node>,

// data specific to each node type:
node_type: NodeType,
}

enum NodeType {
Text(String),
Element(ElementData),
}

struct ElementData {
tag_name: String,
attributes: AttrMap,
}

type AttrMap = HashMap<String, String>;


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

fn elem(name: String, attrs: AttrMap, children: Vec<Node>) -> Node {
Node {
children: children,
node_type: NodeType::Element(ElementData {
tag_name: name,
attributes: attrs,
})
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 5568f63

Please sign in to comment.