Stream: ideas

Topic: ✔ How to borrow something with given lifetime?


view this post on Zulip Locria Cyber (Nov 10 2021 at 02:13):

@Richard Feldman

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:13):

Related to https://github.com/rtfeldman/roc/pull/1866

view this post on Zulip Richard Feldman (Nov 10 2021 at 02:30):

sorry, what's the question?

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:30):

clap's API only borrows str with lifetime.

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:30):

I used a workaround by allocating Strings of backends in main

view this post on Zulip Richard Feldman (Nov 10 2021 at 02:34):

can you link me to a specific line of code in the PR?

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:37):

inside src/lib.rs build_app()

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:37):

https://docs.rs/clap/2.33.3/clap/struct.Arg.html#method.possible_value

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:37):

clap doesn't take ownership of str used

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:38):

So you have to allocate that in main to keep clap happy

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:47):

lazy_static is elegant for "compile-time variables" since Rust has poor support for CTFE

view this post on Zulip Locria Cyber (Nov 10 2021 at 02:47):

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();
   |                                     ^^^^^^^^^^^^^^^^^^

view this post on Zulip Richard Feldman (Nov 10 2021 at 02:52):

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

view this post on Zulip Richard Feldman (Nov 10 2021 at 02:53):

that's probably an acceptable amount of overhead here, but it makes me want to avoid lazy_static by default

view this post on Zulip Richard Feldman (Nov 10 2021 at 02:54):

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

view this post on Zulip Notification Bot (Nov 10 2021 at 02:56):

Locria Cyber has marked this topic as resolved.


Last updated: Jun 16 2026 at 16:19 UTC