refactor: create timeout/retry utilities to reduce code duplication (P1.1)
Created new utility modules to eliminate repeated timeout/retry patterns: - src/utils/retry.rs: with_timeout() and with_timeout_msg() helpers - src/utils/formatting.rs: timestamp formatting utilities (from utils.rs) - src/utils/tdlib.rs: TDLib log configuration utilities (from utils.rs) Refactored src/input/main_input.rs: - Replaced 18+ instances of timeout(Duration, op).await pattern - Simplified error handling from nested Ok(Ok(...))/Ok(Err(...))/Err(...) to cleaner Ok(...)/Err(...) with custom timeout messages - Added type annotations for compiler type inference Benefits: - Reduced code duplication from ~20 instances to 2 utility functions - Cleaner, more readable error handling - Easier to maintain timeout logic in one place - All 59 tests passing Progress: REFACTORING_OPPORTUNITIES.md #1 (Дублирование кода) - Частично выполнено Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
23
src/utils/tdlib.rs
Normal file
23
src/utils/tdlib.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[link(name = "tdjson")]
|
||||
extern "C" {
|
||||
fn td_execute(request: *const c_char) -> *const c_char;
|
||||
}
|
||||
|
||||
/// Отключаем логи TDLib синхронно, до создания клиента
|
||||
pub fn disable_tdlib_logs() {
|
||||
let request = r#"{"@type":"setLogVerbosityLevel","new_verbosity_level":0}"#;
|
||||
let c_request = CString::new(request).unwrap();
|
||||
unsafe {
|
||||
let _ = td_execute(c_request.as_ptr());
|
||||
}
|
||||
|
||||
// Также перенаправляем логи в никуда
|
||||
let request2 = r#"{"@type":"setLogStream","log_stream":{"@type":"logStreamEmpty"}}"#;
|
||||
let c_request2 = CString::new(request2).unwrap();
|
||||
unsafe {
|
||||
let _ = td_execute(c_request2.as_ptr());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user