A tiny experimental browser engine implemented in Rust. It parses a hard-coded HTML string into a DOM and "renders" it by pretty-printing the node tree to the terminal. This is mainly for learning and experimentation with parsing, DOM construction, and rendering logic.
- Rust toolchain (recommended: install via rustup)
cargoavailable on yourPATH
- Supported platforms: Developed and tested on macOS, but it should work anywhere Rust does.
- Clone the repository
git clone <your-repo-url> browser_engine
cd browser_engine- Verify Rust is installed
rustc --version
cargo --versionIf these commands fail, install Rust from https://rustup.rs.
From the project root:
cargo buildThis will compile the browser_engine binary into the target/debug directory.
From the project root:
cargo runThis will:
- Parse the hard-coded HTML string defined in
src/main.rs - Build a DOM tree via the
htmlanddommodules - Render/pretty-print the resulting node tree to the terminal via the
drawmodule
You can change the HTML input by editing the string in src/main.rs (look for the html variable inside the main function).
Cargo.toml– Rust package manifest and metadatasrc/main.rs– Binary entrypoint wiring together parsing and drawingsrc/html.rs– HTML parser and related logicsrc/dom.rs– DOM node definitions and tree representationsrc/draw.rs– Rendering/pretty-printing of the DOM tree to the terminal
- Format the code
cargo fmt- Run with debug output
You can addprintln!calls insidehtml,dom, ordrawmodules to inspect intermediate structures while learning how the engine works.
-
Build fails:
- Ensure you are using a recent Rust toolchain (
rustc --version) compatible with the2024edition. - Run
cargo clean && cargo buildto force a fresh build.
- Ensure you are using a recent Rust toolchain (
-
Binary not found:
- Always run from the project root with
cargo run. Cargo will handle building and running thebrowser_enginebinary for you.
- Always run from the project root with