1 unstable release
0.1.0 | Jul 11, 2022 |
---|
#2920 in Rust patterns
18KB
456 lines
const_stringify_ints
Converts (generic) constant integers to &'static str
.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
This library solves a very specific problem: You have a (possibly generic) constant integer, and you want it as a &'static str
.
All methods are named const_str_
and then the type.
use const_stringify_ints::*;
const SIZE_OF_MY_ARR:usize = 294;
const SIZE_STR:&'static str = const_str_usize::<SIZE_OF_MY_ARR>();
assert_eq!(SIZE_OF_MY_ARR.to_string().as_str(), SIZE_STR);
Support
This library supports no_std
environments.
This library should in theory support targets with a 16-bit, however I don't have a way of testing this. Additionaly, these targets are likely very memory-constrained, and this crate always 'allocates' 5 bytes of static memory for a u16
even when only 1 byte is needed.