Description
Proc macros are clunky and error-prone. Problems include:
- You cannot depend on
icu_locid_macros
by itself; you need to include eithericu
oricu_locid
- They are heavier than
macro_rules!
andconst fn
, since the compiler needs to link and run them as a separate binary - The macros crate needs to be published separately on crates.io
- Pulls in a nontrivial
proc-macro-crate
dependency in Cargo.toml
We are close to being able to write the locale macros as const functions.
I previous said in #310 (comment):
Okay, I also do not see any sign of string/slice indexing operations. I saw it suggested in rust-lang/rust#52000 that this could change (allowing
for
loops), but there doesn't seem to be a lot of movement on the idea of the fundamental indexing operation in const functions.That being said, since we can pretty trivially implement things like
TinyStr4::is_ascii_alphabetic()
as const functions, we could limit the locale macro to be along the lines oflangid!("en") langid!("en", "US") langid!("en", "Latn", "US")
We can validate the subtags, but we can't parse the
"en-Latn-US"
syntax inside the const function in any clean way. (I guess you could convert the string to a TinyStr16 and do bitwise operations on that...)
I think we should consider this route as a more future-proof solution to this problem.