Axel
Axel

Reputation: 5111

How to use variables declared inside a struct from within a struct in Rust?

struct Parser;

impl Parser {
    const ALPHABETS_UPPERCASE: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  ];

  fn get_alphabet(&self) {
    self::..
  }
}

How to access ALPHABETS_UPPERCASE inside get_alphabet function?

Upvotes: 1

Views: 59

Answers (1)

prog-fh
prog-fh

Reputation: 16785

Self::ALPHABET_UPPERCASE (and not self) since this constant takes place in Parser as a whole and not a peculiar instance.

See here.

Upvotes: 3

Related Questions