Trangar / periodic_table

Library that provides a list of elements in the periodic table
3 stars 1 forks source link

Switch to lazy static initialization for the element table #5

Closed noirotm closed 4 years ago

noirotm commented 4 years ago

This turns the element table into a lazy static Vec, and modifies the public function to rely on it. In order to avoid exposing a Vec or a lazy_static internal type, the function returns a slice directly.

Note that we cannot return a Vec directly because it would need to move out of the static. To make it work, we'd need to clone the Vec instead, which would defeat the purpose of using a static variable in the first place.