@Richard Feldman
Related to https://github.com/rtfeldman/roc/pull/1866
sorry, what's the question?
clap's API only borrows str with lifetime.
I used a workaround by allocating Strings of backends in main
can you link me to a specific line of code in the PR?
inside src/lib.rs build_app()
https://docs.rs/clap/2.33.3/clap/struct.Arg.html#method.possible_value
clap doesn't take ownership of str used
So you have to allocate that in main to keep clap happy
lazy_static is elegant for "compile-time variables" since Rust has poor support for CTFE
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> cli/src/main.rs:27:37
|
27 | const default_backend: String = Backend::default().to_string();
| ^^^^^^^^^^^^^^^^^^
yeah, but it's more expensive than actually static things, or even inline things, because it has to do a lock on every dereference to prevent data races
that's probably an acceptable amount of overhead here, but it makes me want to avoid lazy_static by default
regarding the earlier question - it looks like if we can't get a static lifetime for those, then we probably do need to do a heap allocation
Locria Cyber has marked this topic as resolved.
Last updated: Jun 16 2026 at 16:19 UTC