Michael-F-Bryan/gcode-rs

A streaming gcode parser built with embedded applications in mind

G-code

110

419 commits

updated Aug 9, 2026

See the code

README

GCode

Crates.io version Docs CI

A gcode parser designed for use in #[no_std] environments. G-code is the common name for the programming language used by CNC machines and 3D printers.

Design goals:

  • embedded-friendly (no_std / WebAssembly)
  • deterministic memory (optional zero allocation via the core visitor API)
  • error-resistant parsing with diagnostics, and
  • O(n) performance with no backtracking.

Default features: alloc, serde. Omit alloc for zero-allocation parsing via the core visitor API. Requires Rust 1.85+.

Getting Started

First, add gcode to your dependencies:

$ cargo add gcode

Then, you can start using it. Here is a simple example that parses a G-code program using the alloc feature:

fn main() -> Result<(), gcode::Diagnostics> {
    let src = "G90 G00 X10 Y20";
    let program = gcode::parse(src)?;
    assert_eq!(program.blocks.len(), 1);
    Ok(())
}

For a visitor-based example, see the pretty_print_visitor example. Run it with cargo run --example pretty_print_visitor.

License

This project is licensed under either of

at your option.

It is recommended to always use cargo-crev to verify the trustworthiness of each of your dependencies, including this one.

Contribution

The intent of this crate is to be free of soundness bugs. The developers will do their best to avoid them, and welcome help in analyzing and fixing them.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

3d-printing
embedded
gcode

Significant stargazers

Adrien Tétar

138 followers · starred Nov 2017

Ted Mielczarek

197 followers · starred May 2017

Max Orok

28 followers · starred May 2020

Michael-F-Bryan/gcode-rs

A streaming gcode parser built with embedded applications in mind

G-code

110

419 commits

updated Aug 9, 2026

See the code

README

GCode

Crates.io version Docs CI

A gcode parser designed for use in #[no_std] environments. G-code is the common name for the programming language used by CNC machines and 3D printers.

Design goals:

  • embedded-friendly (no_std / WebAssembly)
  • deterministic memory (optional zero allocation via the core visitor API)
  • error-resistant parsing with diagnostics, and
  • O(n) performance with no backtracking.

Default features: alloc, serde. Omit alloc for zero-allocation parsing via the core visitor API. Requires Rust 1.85+.

Getting Started

First, add gcode to your dependencies:

$ cargo add gcode

Then, you can start using it. Here is a simple example that parses a G-code program using the alloc feature:

fn main() -> Result<(), gcode::Diagnostics> {
    let src = "G90 G00 X10 Y20";
    let program = gcode::parse(src)?;
    assert_eq!(program.blocks.len(), 1);
    Ok(())
}

For a visitor-based example, see the pretty_print_visitor example. Run it with cargo run --example pretty_print_visitor.

License

This project is licensed under either of

at your option.

It is recommended to always use cargo-crev to verify the trustworthiness of each of your dependencies, including this one.

Contribution

The intent of this crate is to be free of soundness bugs. The developers will do their best to avoid them, and welcome help in analyzing and fixing them.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

3d-printing
embedded
gcode

Significant stargazers

Adrien Tétar

138 followers · starred Nov 2017

Ted Mielczarek

197 followers · starred May 2017

Max Orok

28 followers · starred May 2020

Languages

G-code

71.2%

Rust

28.8%