diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-06-09 01:44:36 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-06-09 01:44:36 +0800 |
| commit | 49192dbb98e0ab1f2a66b4786fac86d63f69be64 (patch) | |
| tree | 7cdf27c7cab5fb6b1aabc2ac7c44b7b492558945 /src | |
| parent | c9dbba0d288becb7f05cebe526be25c76e5a850a (diff) | |
重构所有部分
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/logger_utils.rs | 10 | ||||
| -rw-r--r-- | src/macros.rs | 9 | ||||
| -rw-r--r-- | src/string_utils.rs | 16 |
4 files changed, 32 insertions, 7 deletions
@@ -1,3 +1,5 @@ pub mod console_utils; pub mod logger_utils; -pub mod convert_utils;
\ No newline at end of file +pub mod convert_utils; +pub mod macros; +pub mod string_utils;
\ No newline at end of file diff --git a/src/logger_utils.rs b/src/logger_utils.rs index 77b136e..543b706 100644 --- a/src/logger_utils.rs +++ b/src/logger_utils.rs @@ -1,7 +1,7 @@ use env_logger::Builder; -use log::{info, LevelFilter}; +use log::LevelFilter; -pub fn logger_build () { +pub fn logger_build(level: LevelFilter) { Builder::new() .format(|buf, record| { use std::io::Write; @@ -15,8 +15,6 @@ pub fn logger_build () { record.args() ) }) - .filter(None, LevelFilter::Info) + .filter(None, level) .init(); - info!("Logger Built.") -} - +}
\ No newline at end of file diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..a7f9dd4 --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,9 @@ +#[macro_export] +macro_rules! entry_mutex { + ($mutex:expr, |$guard:ident| $code:expr) => { + if let Ok(mut $guard) = $mutex.lock() { + let $guard = &mut $guard; + $code + } + }; +}
\ No newline at end of file diff --git a/src/string_utils.rs b/src/string_utils.rs new file mode 100644 index 0000000..7a02f25 --- /dev/null +++ b/src/string_utils.rs @@ -0,0 +1,16 @@ +pub fn process_id_text(input: String) -> String { + let s = input.trim().to_lowercase(); + let mut result = String::new(); + + for c in s.chars() { + match c { + '\n' | '_' => continue, + '-' | '.' | ',' | ' ' => result.push('_'), + _ => result.push(c), + } + } + + result.chars() + .filter(|&c| c.is_ascii_alphanumeric() || c == '_') + .collect() +}
\ No newline at end of file |
