1

I need a "default", de facto an empty struct that I will be returning as a default value. Since it is read only, I don't want to pollute the memory by creating it N times, but rather return it only once

#[derive(Debug,PartialEq)]
pub struct Vocabulary {
    literal_names:  Vec<String>,
    symbolic_names: Vec<String>,
    display_names:  Vec<String>,
    max_toke_type:  usize,
}

static EMPTY_VOCABULARY:Vocabulary = Vocabulary{
    literal_names:  Vec::new(),
    symbolic_names: Vec::new(),
    display_names:  Vec::new(),
    max_toke_type:  0 ,
};

This fails, considering function calls are not allowed in static context. How can I initialized these fields then?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
NeatNerd
  • 2,305
  • 3
  • 26
  • 49

0 Answers0