weldr is a Rust library to manipulate LDraw files (format specification), which are files describing 3D models of LEGO®* pieces.
weldr allows building command-line tools and applications leveraging the fantastic database of pieces contributed by the LDraw community.
Parse a single .ldr
line containing a file reference command (line type 1):
```rust extern crate weldr; use weldr::read_lines;
fn main() {}
fn parsefileref() { let ldr = b"1 16 0 0 0 1 0 0 0 1 0 0 0 1 s/6143.dat"; let data = readlines(ldr); let res = CommandType::SubFileRef(SubFileRefCmd{ color: 16, pos: Vec3{ x: 0.0, y: 0.0, z: 0.0 }, row0: Vec3{ x: 1.0, y: 0.0, z: 0.0 }, row1: Vec3{ x: 0.0, y: 1.0, z: 0.0 }, row2: Vec3{ x: 0.0, y: 0.0, z: 1.0 }, file: "s/6143.dat" }); asserteq!(data, Ok((&b""[..], vec![res]))); } ```
The read_lines()
function can be used to parse an entire file too.
weldr was only tested so far with Rustc version 1.47 although older versions may work, but for lack of time have never been tested.
weldr is available on crates.io and can be included in your Cargo enabled project like this:
toml
[dependencies]
weldr = "0.1"
Then include it in your code like this:
```rust,ignore
extern crate weldr; ```
weldr leverages the nom parser combinator library to efficiently and reliably parse LDraw files, and transform them into in-memory data structures for consumption. All parsing is done on &[u8]
input expected to contain specification-compliant LDraw content. In particular, this means:
<CR><LF>
and Unix <LF>
line termination acceptedThe current code repository is licensed under the MIT license.
LDraw™ is a trademark owned and licensed by the Estate of James Jessiman, which does not sponsor, endorse, or authorize this project.
LEGO® is a registered trademark of the LEGO Group, which does not sponsor, endorse, or authorize this project.