From 2dd30931f2aee2f0a0ef653cd26680fe61e413d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Tue, 22 Apr 2025 02:59:23 -0400 Subject: [PATCH] docs(logger): `setup_logger` safety assumptions (#107) --- adb_cli/src/main.rs | 8 +++++++- adb_cli/src/utils.rs | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/adb_cli/src/main.rs b/adb_cli/src/main.rs index b7e0f2f..14605b2 100644 --- a/adb_cli/src/main.rs +++ b/adb_cli/src/main.rs @@ -25,9 +25,15 @@ use std::path::Path; use utils::setup_logger; fn main() -> Result<()> { + // This depends on `clap` let opts = Opts::parse(); - setup_logger(opts.debug); + // SAFETY: + // We are assuming the entire process is single-threaded + // at this point. + // This seems true for the current version of `clap`, + // but there's no guarantee for future updates + unsafe { setup_logger(opts.debug) }; // Directly handling methods / commands that aren't linked to [`ADBDeviceExt`] trait. // Other methods just have to create a concrete [`ADBDeviceExt`] instance, and return it. diff --git a/adb_cli/src/utils.rs b/adb_cli/src/utils.rs index 57e49f5..b5b01db 100644 --- a/adb_cli/src/utils.rs +++ b/adb_cli/src/utils.rs @@ -1,4 +1,8 @@ -pub fn setup_logger(debug: bool) { +/// # Safety +/// +/// This conditionally mutates the process' environment. +/// See [`std::env::set_var`] for more info. +pub unsafe fn setup_logger(debug: bool) { // RUST_LOG variable has more priority then "--debug" flag if std::env::var("RUST_LOG").is_err() { let level = match debug {