rumtk-core 0.20.2

Core library for providing general functionality to support the other RUMTK crates. See rumtk-hl7-v2 crate as example
Documentation
/*
 *     rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
 *     This toolkit aims to be reliable, simple, performant, and standards compliant.
 *     Copyright (C) 2026  Luis M. Santos, M.D. <lsantos@medicalmasses.com>
 *     Copyright (C) 2026  MedicalMasses L.L.C. <contact@medicalmasses.com>
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

use crate::base::RUMResult;
use crate::cache::{new_cache, LazyRUMCache};
use crate::hash::hash_data;
use crate::strings::{rumtk_format, RUMString};
use crate::types::RUMHashMap;
use regex::Regex;
use rumtk_arena::base::RUMVec;
use std::fmt::Debug;
/**************************** Globals **************************************/
static mut RE_CACHE: RUMRegexCache = new_cache();
/**************************** Constants**************************************/
pub const DEFAULT_REGEX_CACHE_PAGE_SIZE: usize = 10;
/**************************** Types *****************************************/
pub type RUMRegex = Regex;
pub type RUMRegexCache = LazyRUMCache<usize, RUMRegex>;
pub type SearchGroups = RUMHashMap<RUMString, RUMString>;
pub type CapturedList<'a> = RUMVec<&'a str>;

/**************************** Traits ****************************************/

/**************************** Helpers ***************************************/
#[inline]
pub fn compile_regex(expr: &str) -> RUMResult<RUMRegex> {
    match Regex::new(expr) {
        Ok(regex) => Ok(regex),
        Err(e) => Err(rumtk_format!("Invalid regex => {}", e))
    }
}

#[inline]
pub fn get_regex_cache() -> &'static mut RUMRegexCache {
    unsafe { &mut RE_CACHE }
}

#[inline]
pub fn hash_regex_expression(expr: &str) -> usize {
    hash_data(expr) as usize
}