Skip to content

Commit

Permalink
Remove lazy_static
Browse files Browse the repository at this point in the history
This crate is not needed anymore since all its functionality has been
merged into the standard library over time.
  • Loading branch information
senekor committed Aug 25, 2024
1 parent d47d407 commit 34d4914
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion exercises/practice/pig-latin/.meta/Cargo-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ version = "1.0.0"

[dependencies]
regex = "0.2"
lazy_static = "1.4.0"
17 changes: 8 additions & 9 deletions exercises/practice/pig-latin/.meta/example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[macro_use]
extern crate lazy_static;
extern crate regex;
use std::sync::LazyLock;

use regex::Regex;

Expand All @@ -9,12 +7,13 @@ use regex::Regex;
pub fn translate_word(word: &str) -> String {
// Prevent creation and compilation at every call.
// These are compiled exactly once
lazy_static! {
// Detects if it starts with a vowel
static ref VOWEL: Regex = Regex::new(r"^([aeiou]|y[^aeiou]|xr)[a-z]*").unwrap();
// Detects splits for initial consonants
static ref CONSONANTS: Regex = Regex::new(r"^([^aeiou]?qu|[^aeiou][^aeiouy]*)([a-z]*)").unwrap();
}

// Detects if it starts with a vowel
static VOWEL: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^([aeiou]|y[^aeiou]|xr)[a-z]*").unwrap());
// Detects splits for initial consonants
static CONSONANTS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^([^aeiou]?qu|[^aeiou][^aeiouy]*)([a-z]*)").unwrap());

if VOWEL.is_match(word) {
String::from(word) + "ay"
Expand Down
1 change: 0 additions & 1 deletion exercises/practice/robot-name/.meta/Cargo-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ name = "robot-name"
version = "0.0.0"

[dependencies]
lazy_static = "1.4.0"
rand = "0.3.12"
12 changes: 6 additions & 6 deletions exercises/practice/robot-name/.meta/example.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use lazy_static::lazy_static;
use std::{
collections::HashSet,
sync::{LazyLock, Mutex},
};

use rand::{thread_rng, Rng};
use std::collections::HashSet;
use std::sync::Mutex;

lazy_static! {
static ref NAMES: Mutex<HashSet<String>> = Mutex::new(HashSet::new());
}
static NAMES: LazyLock<Mutex<HashSet<String>>> = LazyLock::new(|| Mutex::new(HashSet::new()));

pub struct Robot {
name: String,
Expand Down

0 comments on commit 34d4914

Please sign in to comment.