From c81b71106ce2e2ed8d4074a91959c6ccb6dc774e Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 13 Sep 2024 22:23:48 +0100 Subject: [PATCH] use hand rolled const str to int --- esp-config/Cargo.toml | 2 +- esp-config/README.md | 4 ++-- esp-config/src/lib.rs | 15 +++++++++++---- esp-wifi/src/lib.rs | 1 - 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/esp-config/Cargo.toml b/esp-config/Cargo.toml index 16407e408f3..d63e892b17a 100644 --- a/esp-config/Cargo.toml +++ b/esp-config/Cargo.toml @@ -2,7 +2,7 @@ name = "esp-config" version = "0.1.0" edition = "2021" -# rust-version = "1.82.0" +rust-version = "1.77.0" [dependencies] diff --git a/esp-config/README.md b/esp-config/README.md index 402a1f358ec..87c7181b0d0 100644 --- a/esp-config/README.md +++ b/esp-config/README.md @@ -2,7 +2,7 @@ [![Crates.io](https://img.shields.io/crates/v/esp-config?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp-config) [![docs.rs](https://img.shields.io/docsrs/esp-config?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp-config) -![MSRV](https://img.shields.io/badge/MSRV-1.82-blue?labelColor=1C2C2E&style=flat-square) +![MSRV](https://img.shields.io/badge/MSRV-1.77-blue?labelColor=1C2C2E&style=flat-square) ![Crates.io](https://img.shields.io/crates/l/esp-config?labelColor=1C2C2E&style=flat-square) [![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) @@ -10,7 +10,7 @@ ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.82 and up. It _might_ +This crate is guaranteed to compile on stable Rust 1.77 and up. It _might_ compile with older versions but that may change in any new patch release. ## License diff --git a/esp-config/src/lib.rs b/esp-config/src/lib.rs index 019ccfdc150..0329f8b2950 100644 --- a/esp-config/src/lib.rs +++ b/esp-config/src/lib.rs @@ -6,12 +6,19 @@ mod generate; pub use generate::*; #[macro_export] +// TODO from 1.82 we can use <$ty>::from_str_radix(env!($var), 10) instead macro_rules! esp_config_int { ($ty:ty, $var:expr) => { - match <$ty>::from_str_radix(env!($var), 10) { - Ok(val) => val, - _ => unreachable!(), - }; + const { + let mut bytes = env!($var).as_bytes(); + let mut val: $ty = 0; + while let [byte, rest @ ..] = bytes { + core::assert!(b'0' <= *byte && *byte <= b'9', "invalid digit"); + val = val * 10 + (*byte - b'0') as $ty; + bytes = rest; + } + val + } }; } diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index e53d7388c58..9177a30f388 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -89,7 +89,6 @@ // toolchain doesn't know about that lint, yet) #![allow(unknown_lints)] #![allow(non_local_definitions)] -#![feature(const_int_from_str)] // stable in 1.82 extern crate alloc;