Skip to content

Commit

Permalink
use hand rolled const str to int
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Sep 13, 2024
1 parent 3905be0 commit c81b711
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion esp-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "esp-config"
version = "0.1.0"
edition = "2021"
# rust-version = "1.82.0"
rust-version = "1.77.0"

[dependencies]

Expand Down
4 changes: 2 additions & 2 deletions esp-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[![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)

## [Documentation](https://docs.rs/crate/esp-config)

## 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
Expand Down
15 changes: 11 additions & 4 deletions esp-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
}

Expand Down
1 change: 0 additions & 1 deletion esp-wifi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c81b711

Please sign in to comment.