From 3b3889967c93cda8cab94b7c410c821a18404ee5 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 18 May 2020 13:54:43 -0600 Subject: [PATCH] refactor: extract `"0x"` literal into `HEX_PREFIX` --- src/bin/hexyl.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index e85ac59..0e39fe3 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -162,8 +162,10 @@ fn main() { } fn parse_hex_or_int(n: &str) -> Option { - if n.starts_with("0x") { - let n = n.trim_start_matches("0x"); + const HEX_PREFIX: &'static str = "0x"; + + if n.starts_with(HEX_PREFIX) { + let n = n.trim_start_matches(HEX_PREFIX); if n.chars().next() == Some('+') { return None; }