Function ocr

Source
pub fn ocr<T: Scannable>(image: T) -> Option<String>
Expand description

Takes an image containing Advent of Code’s ASCII-art letter representations and converts it to a standard String.

image is a Scannable, which is a marker trait that is implemented for the following types:

  • &str
  • (&Vec<bool>, usize), a tuple consisting of a Vec of bools and the width of a line.
  • (&Vec<bool>, usize), a tuple consisting of a Vec of chars and the width of a line.
  • &Vec<Vec<bool>>, a Vec of a Vec of bools.
  • &Vec<Vec<char>>, a Vec of a Vec of chars.

For &str and the char-based Vecs, ‘#’ is considered part of a letter and all other chars are considered blank space. For the bool-based Vecs, true is considered part of a letter and false is considered blank space.

§Example

use advent_ocr::ocr;
 
let image = r"
.##..###...##.
#..#.#..#.#..#
#..#.###..#...
####.#..#.#...
#..#.#..#.#..#
#..#.###...##.
    ";
 
let s = ocr(image).unwrap();
assert_eq!(s, "ABC");