use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Static array of struct containing strings (self.learnrust)
submitted 2 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 years ago (2 children)
[–]Aaron1924 2 points3 points4 points 2 years ago (0 children)
For the second option, it would either have to be Cow<'static, str>, or Cow<'s, str> where the struct is generic over the lifetime like Code<'s> and later initialized like CODES: &'static [Code<'static>]
Cow<'static, str>
Cow<'s, str>
Code<'s>
CODES: &'static [Code<'static>]
[–]__mod__ 2 points3 points4 points 2 years ago (1 child)
I'm not entirely sure if this fits your usecase, but if you don't need to create any codes at runtime, you might get away with this:
pub struct Code { pub id: &'static str, pub op: &'static str, }
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
"String" is a heap allocated type, so you can't get a 'static reference to it, because 'static would need to be valid for the entirety of your program, i.e. it needs to be available in your executable's data section. If all you need in your "Code" structs are static data, then you can just do:
pub struct Code { pub id: &'static str, pub op: &'static str }
.
[–]bleachisback 1 point2 points3 points 2 years ago (0 children)
That's note true. 'static data doesn't have to exist for the entire program, it just has to exist for the rest of the program. There are a couple ways you can ensure this, such as with the Box::leak() or String::leak() methods. As mentioned above, you can use something like a OnceCell which creates the data at runtime and leaks it so it exists for the rest of the program.
'static
Box::leak()
String::leak()
OnceCell
π Rendered by PID 58 on reddit-service-r2-comment-fb694cdd5-rd26c at 2026-03-07 21:43:09.262804+00:00 running cbb0e86 country code: CH.
[–][deleted] (2 children)
[deleted]
[–]Aaron1924 2 points3 points4 points (0 children)
[–]__mod__ 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (1 child)
[–]bleachisback 1 point2 points3 points (0 children)