Unique characters mapped to enums in Rust

I write a simple program to parse lines read from a file.
As I am new to Rust, I wonder if I create too much mat.

An example of a line in the file looks like this: pqrXYZ12a9.
Char in position 8 (from 0) can be a, b or c and say that it represents a kind of "category".

I'm thinking of modeling this specific area with a enum.
I then realized that I needed a function to analyze the real value of the specific variant.

Here is my code – questions after:

enum Category {

fn parse_category (line: String) -> Category {
leave category = & line[8 .. 9];
match category {
"a" => Category: A,
"b" => Category: B,
"c" => Category: C,
_ => panic! (),

fn main () {
let test_string = String :: from ("pqrXYZ12a9");

match parse_category (test_string) {
Category: A => println! ("Cat A"),
Category :: B => println! ("Cat B"),
Category: C => println! ("Cat C"),

Things I'm not sure are:

  • Can I avoid creating a parse_category function and assign the specific letter to Category variants? In fact, should I or should not I? Something like:

    // do not compile
    enum Category {
    A = & # 39;


  • Is it possible to "name the slice" in parse_category? I'd like to avoid putting magic numbers here and there and having all the fields defined somewhere together.
    In Python, I would create a slice object such as category_field = slice (8, 9) then pass it as line[category_field].

  • Any other comment is welcome.