#How to handle error in lazy static ?

3 messages · Page 1 of 1 (latest)

vital spade
#
use lazy_static::lazystatic;

lazy_static! {
  static ref ABC: Regex = Regex::new(r"(.*)").unwrap();  
}

I want to remove the unwrap() and handle error...

use lazy_static::lazystatic;

lazy_static! {
  static ref ABC: Result<Regex, Error> = Regex::new(r"(.*)")?;  
}

I also tried to use a match statement , and if let on ABC,
But it says ABC is a struct and it is match to Result

unkempt hornet
#

also I suggest using oncecell::sync::Lazy over lazy_static