basic_usage/
basic_usage.rs1use puz_parse::{parse, parse_bytes, parse_file};
2use std::fs::File;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 println!("=== Simple File Parsing ===");
7 let puzzle = parse_file("examples/data/standard1.puz")?;
8 println!("Title: {}", puzzle.info.title);
9 println!("Author: {}", puzzle.info.author);
10 println!("Size: {}x{}", puzzle.info.width, puzzle.info.height);
11 println!();
12
13 println!("=== Advanced Parsing with Warnings ===");
15 let file = File::open("examples/data/rebus.puz")?;
16 let result = parse(file)?;
17 let puzzle = result.result;
18
19 println!("Title: {}", puzzle.info.title);
20
21 for warning in &result.warnings {
23 println!("Warning: {warning}");
24 }
25 println!();
26
27 println!("=== Working with Clues ===");
29 println!("Across clues:");
30 for (num, clue) in puzzle.clues.across.iter().take(5) {
31 println!(" {num}: {clue}");
32 }
33
34 println!("Down clues:");
35 for (num, clue) in puzzle.clues.down.iter().take(5) {
36 println!(" {num}: {clue}");
37 }
38 println!();
39
40 println!("=== Working with the Grid ===");
42 println!("First few rows of solution:");
43 for (i, row) in puzzle.grid.solution.iter().take(3).enumerate() {
44 println!(" Row {}: {}", i + 1, row);
45 }
46
47 println!("First few rows of blank grid:");
48 for (i, row) in puzzle.grid.blank.iter().take(3).enumerate() {
49 println!(" Row {}: {}", i + 1, row);
50 }
51 println!();
52
53 println!("=== Working with Extensions ===");
55 if let Some(rebus) = &puzzle.extensions.rebus {
56 println!("Rebus found! Entries:");
57 for (key, value) in &rebus.table {
58 println!(" {key}: {value}");
59 }
60 } else {
61 println!("No rebus in this puzzle");
62 }
63
64 if let Some(_circles) = &puzzle.extensions.circles {
65 println!("This puzzle has circled squares");
66 } else {
67 println!("No circled squares in this puzzle");
68 }
69
70 if let Some(_given) = &puzzle.extensions.given {
71 println!("This puzzle has given squares");
72 } else {
73 println!("No given squares in this puzzle");
74 }
75 println!();
76
77 println!("=== Parsing from Bytes ===");
79 let data = std::fs::read("examples/data/standard1.puz")?;
80 let puzzle_from_bytes = parse_bytes(&data)?;
81 println!("Parsed from bytes: {}", puzzle_from_bytes.info.title);
82
83 Ok(())
84}