From e8ab791f511a66bd185ffd66bf84df09d83e3a6b Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Mon, 10 Feb 2025 13:19:12 +0100 Subject: [PATCH] Remove the dependency on `parse_int` in favour of `from_str_radix` --- Cargo.lock | 1 - espflash/Cargo.toml | 2 -- espflash/src/cli/mod.rs | 10 ++++++++-- espflash/src/cli/monitor/parser/mod.rs | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61846e14..82432823 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1272,7 +1272,6 @@ dependencies = [ "log", "md-5", "miette", - "parse_int", "regex", "serde", "serialport", diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index 1523cf31..22031259 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -43,7 +43,6 @@ indicatif = { version = "0.17.9", optional = true } log = "0.4.22" md-5 = "0.10.6" miette = "7.4.0" -parse_int = { version = "0.6.0", optional = true } regex = { version = "1.11.1", optional = true } serde = { version = "1.0.217", features = ["derive"] } serialport = { version = "4.7.0", default-features = false, optional = true } @@ -73,7 +72,6 @@ cli = [ "dep:directories", "dep:env_logger", "dep:indicatif", - "dep:parse_int", "dep:toml", "dep:update-informer", "miette/fancy", diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 4ec099c2..9d5e8405 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -290,9 +290,15 @@ pub struct ChecksumMd5Args { connect_args: ConnectArgs, } -/// Parses an integer, in base-10 or hexadecimal format, into a [u32]. +/// Parses an integer, in base-10 or hexadecimal format, into a [u32] pub fn parse_u32(input: &str) -> Result { - parse_int::parse(input) + let (s, radix) = if matches!(&input[0..2], "0x" | "0X") { + (&input[2..], 16) + } else { + (input, 10) + }; + + u32::from_str_radix(s, radix) } /// Select a serial port and establish a connection with a target device diff --git a/espflash/src/cli/monitor/parser/mod.rs b/espflash/src/cli/monitor/parser/mod.rs index a9266400..d48f555d 100644 --- a/espflash/src/cli/monitor/parser/mod.rs +++ b/espflash/src/cli/monitor/parser/mod.rs @@ -16,7 +16,7 @@ pub trait InputParser { } // Pattern to much a function address in serial output. -static RE_FN_ADDR: LazyLock = LazyLock::new(|| Regex::new(r"0x[[:xdigit:]]{8}").unwrap()); +static RE_FN_ADDR: LazyLock = LazyLock::new(|| Regex::new(r"0[xX][[:xdigit:]]{8}").unwrap()); fn resolve_addresses( symbols: &Symbols<'_>, @@ -30,7 +30,7 @@ fn resolve_addresses( // Since our regular expression already confirms that this is a correctly // formatted hex literal, we can (fairly) safely assume that it will parse // successfully into an integer. - let addr = parse_int::parse::(matched).unwrap(); + let addr = u64::from_str_radix(&matched[2..], 16).unwrap(); let name = symbols.get_name(addr); let location = symbols.get_location(addr);