Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy_static #1990

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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